A
A
Alksar2015-04-21 21:09:59
Programming
Alksar, 2015-04-21 21:09:59

Question for those who have recently read Bob Martin's book - "agile development technique in c #".?

In his book, Bob develops an application using the "transaction list" architecture; for each operation in the system, its own class is created, inherited from the "Transaction" class with the "Execute ()" method, remember?
So, all the "ChangeEmployeeTransaction" operations that change some fields of the Employee object load the employee's EmpId from the database, change the required field, but do not save the result back to the database. This is not indicated anywhere, and this is not in the finished code either. How so? Maybe I missed something?
For example, the code of the abstract class ChangeEmployeeTransaction and the concrete class, ChangeNameEmployeeTransaction, which implements the base one:

public abstract class ChangeEmployeeTransaction : Transaction
{
   private readonly int empId;
   public ChangeEmployeeTransaction(int empId)
   {
      this.empId = empId;
   }
   public void Execute()
   {
      Employee e = PayrollDatabase.GetEmployee(empId);
      if(e != null)
         Change(e);
      else
         throw new InvalidOperationException(
              “Работник не найден.”);
   }
   protected abstract void Change(Employee e);
}

public class ChangeNameTransaction : ChangeEmployeeTransaction
{
   private readonly string newName;
   public ChangeNameTransaction(int id, string newName)
      : base(id)  { this.newName = newName; }
   protected override void Change(Employee e)
   {
      e.Name = newName;
   }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2015-04-21
Protko @Fesor

I didn’t read it, but I suspect that the saving logic is placed just the same in the Execute method (that is, it is not implemented, and probably should be implemented within the PayrollDatabase), that is, outside of Change. I would have shoved Unit-of-work there, then it’s generally nice.

M
Maxim Kuznetsov, 2015-04-29
@max-kuznetsov

Look for an implementation of the Change(e); This method makes changes and saves the result.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question