Avoiding anemic domain model - a real example -


I am trying to understand the anemic domain model and that is why they are an anti-pattern.

Here is a real world example.

I have an employee class with a ton of properties - name, gender, username, etc.

  public class employee {public string name {receipt; Set; } Public string gender {receipt; Set; } Public String Username {get; Set; } // etc .. Most Gates and Sets}} Next we have a system in which incoming phone calls and website inquiries (known as 'Leeds') Equally the sales staff has been equally involved. This system is quite complicated, because it involves round robining inquiries, checking for vacations, employee preferences etc. So this system is currently different in a service outside: EmployeeLeadRotationService  
  Public class EmployeeLeadRotationService:. IEmployeeLeadRotationService {Private IEPG repository _employeeRepository; // ... many other injected repositories and services Public Zero Selector (IIILID Lead) {// etc. Lots of complex logic}}  

Then the form behind our website check We have such code in:

  public zeros submitForm () {var lead = CreateLeadFromFormInput (); Var selectedEmployee = Kernel.Get & lt; IEmployeeLeadRotationService & gt; () .SelectEmployee (lead); reaction. Write (employee name + "will handle your inquiry. Thanks."); }  

I do not really have to face many problems with this approach, but it is believed that it is screaming me because it is a bloodless model model Is.

But for me it is not clear where the logic in the main rotation service should go. Should it go in leadership? Should it go to the employee?

If the rotation service is required, then about these injected repositories, etc. - how the injection will be given to the employee, given that most employees, when dealing with an employee, will be given any of these repositories Do not need

In this case it does not constitute an immemorial domain model; For example, if an external work actually changes the status of the employee or updated their details.

What is happening in this case, are you taking all the employees and selecting one of them based on their information, it is a different object, which examines others and its Decides about who gets it. An object is used to move one object from one state to another in another state.

An example of an unmanned domain model in your case would be an external method

updateHours (employee EMP) // updates the working hours of the employee

Which acts as an employee and updates his hours for the week, the problem with this is to ensure that the flags have been taken if the hours are more than a certain limit. If you have only employee items, then you have to It is not how to amend your hours within the right odds. In this case, the way of settling it, the updating staff will have to be taken to the staff. This is the root cause of anemic domain model anti-pattern.


Comments