Verification method in OOP – DDD

I have a question about the verification method in ddd. I have read quite controversial opinions. Some people say this should be physical life, some people say it should be placed in the entity. I am Trying to find a method I can follow.

For example, suppose I have User entity, which contains email and password. User has method to register (email, password). Email and password Where should the verification be placed? I personally think it should be in the Register() method. But this method may cause confusion between the User class and the authentication content. One method may be to extract the email and password rules in a separate policy object and still get it from Register() Method to call them.

What is your opinion on DDD verification methods?

First of all, I think validation is a slippery theme to some extent, partly because of the need Various contexts considered. Eventually, validation rules will be implemented at various application layers. At least, there should be standard protections in domain objects. These are just regular preconditions and parameter checks, and should be part of any well-designed object. And in line with your opinion on the Reigster method. As lazyberezovsky said, this is to prevent objects from entering an invalid state. I support schools that are always valid. I think if you need to persist an entity into an invalid state, you should create a new entity for this purpose

However, only one problem with this method is that these validation rules usually need to be exported to other layers, such as the presentation layer. In addition, in the presentation layer, the rules need to be formatted in a different format They need to be rendered once and may be converted to another language, such as JavaScript, for immediate client-side feedback. Trying to extract validation rules from exceptions raised by the class may be difficult or impractical. Alternatively, they can be expressed in The layer recreates the validation rules. This is simpler, although it may violate DRY, it allows the rules to depend on the context. A particular workflow may require different validation rules than the entity itself enforces.

The method described Another problem is that there may be validation rules that are beyond the scope of the entity, and these rules must be merged with other rules. For example, for user registration, another rule is to ensure that email addresses are unique. Application services hosting applicable use cases usually do Enforce this rule. However, it must also be able to export this rule to other layers, such as presentations.

In general, I try to put as many constraint checks as possible into the entity itself, because I Believe that entities should always be valid. Sometimes you can design the rule framework so that it can be used to raise exceptions and export to the outer layer. Other times, it is easier to simply copy the rules across layers.

< p>I have a question about the verification method in ddd. I have read quite controversial opinions. Some people say this should be physical life, some people say this should be put in the entity. I am trying to find a way I can follow

For example, suppose I have a User entity, which contains email and password. Users have methods to register (email, password). Where should email and password verification be placed? I personally think it should be in the Register() method. But this method may cause confusion between the User class and the authentication content. One method may be to extract the email and password rules in a separate policy object and still get it from Register() Method to call them.

What is your opinion on DDD verification methods?

First of all, I think verification is a slippery theme to some extent, partly because of the various contexts that need to be considered. In the end, it will be in various The application layer enforces the validation rules. At least, there should be standard protections in the domain object. These are just regular preconditions and parameter checks, and should be part of any well-designed object and conform to your opinion of the Reigster method. As lazyberezovsky said Say, this is to prevent objects from entering an invalid state. I support schools that are always valid. I think if you need to persist an entity into an invalid state, you should create a new entity for this purpose.

However , Only one problem with this method is that these validation rules usually need to be exported to other layers, such as the presentation layer. In addition, in the presentation layer, the rules need to be formatted in different formats. They need to be presented at once and may be converted to Another language, such as JavaScript, for immediate client-side feedback. Trying to extract validation rules from exceptions raised by the class can be difficult or impractical. Alternatively, validation rules can be recreated at the presentation layer. This is simpler, although possible Violates DRY, but it allows the rules to depend on the context. Specific workflows may require different validation rules than those enforced by the entity itself.

Another problem with the described method is that there may be validation rules outside the scope of the entity , And these rules must be merged with other rules. For example, for user registration, another rule is to ensure that email addresses are unique. Application services hosting applicable use cases usually enforce this rule. However, it must also be able to This rule is exported to other layers, such as presentation.

In general, I try to put as many constraint checks as possible into the entity itself, because I think the entity should always be valid. Sometimes a framework of rules can be designed, Make it available to raise exceptions and export to the outer layer. Other times, it is easier to simply copy the rules across layers.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 2302 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.