How to decide whether to implement an operation as Entity operation vs Service operation in Domain Driven Design?

Posted by Louis Rhys on Programmers See other posts from Programmers or by Louis Rhys
Published on 2012-04-03T08:17:56Z Indexed on 2012/04/03 11:40 UTC
Read the original article Hit count: 296

I am reading Evans's Domain Driven Design. The book says that there are entity and there are services. If I were to implement an operation, how to decide whether I should add it as a method on an entity or do it in a service class?

e.g. myEntity.DoStuff() or myService.DoStuffOn(myEntity)?

Does it depend on whether other entities are involved? If it involves other entities, implement as service operation? But entities can have associations and can traverse it from there too right?

Does it depend on stateless or not? But service can also access entities' variable, right? Like in do stuff myService.DoStuffOn, it can have code like

if(myEntity.IsX) doSomething();

Which means that it will depend on the state?

Or does it depend on complexity? How do you define complex operations?

© Programmers or respective owner

Related posts about object-oriented

Related posts about architecture