A weak or anemic domain model simply means that your “domain objects” are DTOs without any behavior. Basically you got a Transaction Script template where DTOs are loaded, modified and saved again. CRUD, in a different way. This is good for many applications that do not have complex enough rules to use the DDD approach.
Domain objects must encapsulate behavior. That is their essence. Any public state (perhaps it does not have public getters or setters) should be read-only, and if you want to change the state, you call a method that relates to the usage / business requirement.
All your "domain logic" should be in these classes. Domain logic is just a fancy name for describing the rules and operational parameters of the domain you choose. Be it banking, retail, HR, etc. When your domain experts explain the “Pay By Card” user case and tell you: “We cannot open until the PDC machine contacts the bank.” This is a business rule / invariant / piecewise domain logic.
Typically, you collect domain objects (consisting of objects and value objects) into aggregates that define the boundary at which a given set of rules should be executed. The object that is the root of this graph of domain objects is known as the "Aggregated Root", and only aggregates the roots so that other objects can contain links. In your case, User is Entity, and since it is the only object in Aggregate, it is also Aggregate Root. For example:
public class User // Entity and also the Aggregate Root { private readonly IList<Friendship> _friends = new List<Friendship>(); public void Befriend(User user) { _friends.Add(new Friendship(, user)); } public class Friendship // Entity {
This is not a good example, because theoretically you would need to call it for each of the two friends in a pair, but any transaction should only perform one operation, not two. In this case, you introduce the concept of Process Managers. These are even more objects that relate to the coordination of what is essentially a long-term transaction (where friends made friends with each other). You are likely to create Friendship (as the aggregate root), and this creation will create some kind of event-driven process in which friends are loaded, made friends and saved.
Neil barnwell
source share