Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Domain driven design: Manager and service

I'm creating some business logic in the application but I'm not sure how or where to encapsulate it, I've used the repository pattern for data access, I've seen some projects that use DDD that have some classes with the "Service" suffix and the "manager" suffix, what are each of this clases suppose to take care of in DDD?

like image 313
ryudice Avatar asked Mar 12 '10 23:03

ryudice


1 Answers

Try to be as specific as possible with the name. As a rule of thumb I would avoid the name "Manager", as its meaning is quite vague.

Typical business logic actors/nouns would be Validators, Rules, Providers, Supervisors, Importers/Exporters, Serializers, Processors (process a transaction), and Repositories (the last of which you already have). If a single class is performing more than one of these functions, it should probably be broken down into subclasses.

You asked the question, "what do these classes take care of?" and indeed, that is the point. The name SomethingManager tells you nothing. OrderValidator, on the other hand, tells you pretty clearly what the class does, as does CustomerHistoryExporter. Services are kind of in the gray area; if the services is named after a passive action, like ShippingService, then it's pretty clear what the service deals with, but a better name might be something like ShipmentDispatcher. You get the idea, I hope.

like image 156
Aaronaught Avatar answered Sep 28 '22 05:09

Aaronaught