oop - How to figure out whether a business action(method) should reside in domain object(class) or domain service(class)? -


according "domain driven design",domain service encapsulates business logic doesn't naturally fit within domain object.the definition of domain service clear,but how can distinguish whether business action belong domain object or domain service.for example have account class,and business action call transfer,both domain service , domain object can finish transfer task.which 1 should choose?

public class account {   public void transfer(account bar)   {      //do   } } public class accountservice {   public void transfer(account foo,account bar)   {      //do   } } 

in "domain driven design" eric evans states:

when significant process or transformation in domain not natural responsibility of entity or value object, add operation model standalone interface declared service.

probably important point here natural responsibility.

since transferring money 1 account not actual responsibility of account, go service approach.

this gets clearer if other actions might related transfer. responsibility of account class encapsulate related data.

examples account responsibilities are:

  • tell current balance (e.g. negative?)
  • tell if account closed
  • tell owner
  • increase or decrease balance
  • show history of balance changes

note these responsibilities refer object or associated or aggregated objects.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -