I want to ask for some advise on how to avoid writing objects which are mere data containers.
Consider the following Aggregate Root:
public class Post : IAggregateRoot
{
List<Comment> Comments {get; set;}
}
Given the pinciples that govern how aggregate roots work, is it valid to call the above code like this?
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 this what Eric Evan means by Aggregate Roots being atomic?
If this is the case, does it mean that Entities do not have any public setters, but instead have supporting Methods (AddThis, RemoveThat)? Is this how you create objects with rich behaviour?