简体   繁体   English

聚合根类是否仅保存公开的方法

[英]Does Aggregate root class holds only publicly exposed methods

I'm trying to understand the concept of AggregateRoots. 我试图理解AggregateRoots的概念。 Let's say that I have a classes Customer , Holiday , Address , Document . 假设我有一个类CustomerHolidayAddressDocument

If I understood correctly an aggregate root should be a class which is in charge of manipulation for certain business rules. 如果我正确理解的话,聚合根应该是负责某些业务规则操纵的类。 In this case, I recognize a Customer class which should be responsible for assigning a holiday record for a given customer as well as other info (address and document). 在这种情况下,我识别出一个Customer类,该类应负责为给定的客户分配假日记录以及其他信息(地址和文件)。

My question(s) is: 我的问题是:

  • Should I follow some filename convention for my aggregate root (CustomerAggregate) instead of Customer? 我应该为我的聚合根目录(CustomerAggregate)而不是客户遵循某种文件名约定吗?
  • Should I make all other classes ( Holiday , Address , Document ) as non-visible to the outside world (aggregate root is the only entry point which uses further those classes, if so what is the best practice for this? 我是否应该将所有其他类( HolidayAddressDocument )设置为对外部世界不可见(聚集根是进一步使用这些类的唯一入口点,如果这样,最佳实践是什么)?
  • Should I structure my aggregate root in a way as domain service class with all possible public entry points (Customer do this, Customer do that) together with all properties for that class? 我是否应该以域服务类的方式构造聚合根,将其包含所有可能的公共入口点(客户这样做,客户这样做)以及该类的所有属性?

In , the usual starting point for aggregates is the Eric Evans book. ,聚合的通常起点是Eric Evans书。

An AGGREGATE is a graph of domain model entities that change together. AGGREGATE是一起更改的域模型实体的图。 Many aggregates will have only a single entity within them, but in general there can be more than one. 许多集合体内将只有一个实体,但通常可以有多个。

An AGGREGATE ROOT is the single entity within an aggregate that the application is allowed to interact with -- the root entity acts as the interface for the entire aggregate. AGGREGATE ROOT是允许应用程序与之交互的聚合中的单个实体-根实体充当整个聚合的接口。 This makes it easier to ensure that the invariant is maintained - all changes have to pass through a single choke point. 这样可以更轻松地确保保持不变-所有更改都必须通过单个阻塞点。

Should I follow some filename convention for my aggregate root (CustomerAggregate) instead of Customer? 我应该为我的聚合根目录(CustomerAggregate)而不是客户遵循某种文件名约定吗?

It doesn't matter a lot, but in most examples the root objects use the naming conventions of an entity in the domain model, rather than having a special convention of their own. 没关系,但是在大多数示例中,根对象使用域模型中实体的命名约定,而不是使用自己的特殊约定。 So Customer would be what you expect to see. 因此, Customer将是您期望看到的。

Should I make all other classes as non-visible to the outside world 我是否应将所有其他课程设置为外界看不见

Not necessarily - the important thing is to ensure that the outside world always goes through the choke point. 不一定-重要的是要确保外部世界始终处于瓶颈。 Using discipline and code review to enforce that is fine . 使用纪律和代码审查来强制执行就可以了 If you are using the repository pattern, you can limit those interfaces to only expose the root objects. 如果使用的是存储库模式,则可以将这些接口限制为仅公开根对象。 In java, you can put all of the entities of an aggregate into a single package, and ensure that only the root object has the public access level modifier. 在Java中,您可以将聚合的所有实体放入单个包中,并确保只有根对象才具有公共访问级别修饰符。

In many cases, it is sufficient to protect against accidental misuse of the model. 在许多情况下,足以防止意外滥用模型。

Should I structure my aggregate root in a way as domain service class with all possible public entry points (Customer do this, Customer do that) together with all properties for that class? 我是否应该以域服务类的方式构造聚合根,将其包含所有可能的公共入口点(客户这样做,客户这样做)以及该类的所有属性?

This question is hard to answer, because domain service is used as a pattern name in -- entities and domain services are different things, so making an aggregate root (which is an entity, see above) like a domain service is a step the wrong direction. 这个问题很难回答,因为domain service用作模式名称-实体和域服务是不同的东西,因此使aggregate root (这是一个实体,请参见上文)就像domain service是错误的方向。

The domain entity will normally include an interface that describes the messages it expects, and also the encapsulated data structure it uses to keep track of its own state. 域实体通常将包括描述其期望的消息的接口,以及用于跟踪其自身状态的封装数据结构。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM