I want to ask for advice on how to avoid writing objects that are just data containers.
Consider the following summary root:
public class Post : IAggregateRoot { List<Comment> Comments {get; set;} }
Given the pinciples that determine how common roots work, is it right to invoke the above code as follows?
new Post().Comments.Add(New Comment("stuff"));
Or is this the right way?
public class Post : IAggregateRoot { List<Comment> Comments {get; private set;} public void AddComment(string message) { Comments.Add(new Comment(message)); } }
And called like this:
new Post().AddComment("stuff");
Is that what Eric Evan means Aggregate Roots are atomic?
If so, does this mean that entities do not have public setters, but instead have supporting methods (AddThis, RemoveThat)? This is how you create rich behavior objects?
design domain-driven-design
Th3fix3r
source share