Does the Save method relate to the essence of the business domain?

I do not use ORM. Therefore, I have a discussion about whether the "Save" method really refers to a business domain entity or should it be abstracted in some service that will be passed to the Business Domain entity for preservation?

eg.

class Employee { string Name; DateTime Birth; GetAge() { } Save() { } } 

OR

 class Employee { string Name; DateTime Birth; GetAge() { } } SomePersistenceService { Save(Employee emp) { } } 
+6
source share
2 answers

Since this question is marked as "domain-driven-design", you will need a repository to do this for you.


Just rename SomePersistenceService to EmployeeRepository. So you were on the right track with your second option. "abstracted in any service that will be transferred to the Entity Business Domain" is called a repository in domain design

A repository is a way to pretend your data warehouse is a collection. So it has methods like Add and Remove instead of Save and Delete .

+2
source

There is no single best solution, the problem you stated is the choice between the repository and the active samples.

As a rule, the repository is more suitable for unit testing, since the repository's interfaces are easily washed out, and the principles of High Cohesion and Single Responsibility are used in the repository template (from the point of view of OOP, it may seem strange that your business object will contain code for saving to your database, transferring yourself over the network or exporting to some XML files, etc.)

Active recording can provide great speed in RAD development, and some tools, such as Spring Roo, were initially developed only to support Active Record, repository support was added only recently, as I know. AFAIK Ruby On Rails uses active writing and some other great tools.

As for Domain Driven Design, you should use the Repository as Jeroen suggested, because the repository is the basic DDD template (this is the central version of the DAO template), but you should check if your tools have direct support for any template,

+3
source

Source: https://habr.com/ru/post/921131/


All Articles