design - DDD - Aggregate Roots and Creating Behavioural Objects -
I want to ask some advice on how to avoid writing objects that are just data containers.
Consider the following total route:
Public class posts: IAggregateRoot {list & lt; Comment & gt; Comments {get}
.tagment. Add (New Comment ("Content"));
Or is this the right way?
Public class posts: IAggregateRoot {list & lt; Comment & gt; Comments {get} Private set;} Public Zero Addcomment (String Message) {Comments. Add (New Comment (Message)); }}
And it was called in such a way:
new post (). AddComment ("stuff");
Does it mean Eric Evan that the total roots mean nuclear?
If this is the case, then this means that institutions do not have any public setters, but instead support methods (AddThis, RemoveThat)? How do you make things with rich behavior?
You have the concept of total roots right, but your two options are really about implementation - and Both of these are valid.
Option 1
-
Pros: Your organization interface is quite clean.
-
Cons:
Add
method requires logic to weld the relationship betweenpost
and. Comment (
(looks NHibernate) You can create a strongly typed archive and override the add method or you can return events toposted
.
Option 2
-
Professionals:
Add / Remove
Methods Provide a convenient location for wiring logic. Cons: As the number of collections increases, you may have aadd / remove
methods explode.
My preference option is 1 - To make sure that, always I use the normal collection which increases the incidence IMHO It sounds more natural, and is easy against code for other developers. Although others have expressed otherwise on the SO.
When we talk about Behavior , we are talking about linking the unit to Logic for example. If you want to stop adding comments
after 5 days, then if you add a post
to a comment
, then valid, and < To post the code>
Comments
Post a Comment