Reputation: 105097
A Network
is composed of Node
s that are connected with Fiber
s. The Network
is responsible for making sure that:
Node
; Node
;Both the Network
, the Node
and the Fiber
are information-rich (they have a name, a date when they were deployed, etc), and it looks to me as if Network
is an Aggregate Root (as its the container of both Node
s and Fibers
and forces invariants between them).
I'm at this point also sure that Node
and Fiber
are entities, and that they are also probably Aggregate Roots.
One possible implementation of the Network
class might be as follows:
class Network {
private final NetworkId id;
private String name;
private Location location;
...
private final Map<FiberId, Fiber> fibers = new HashMap<FiberId, Fiber>();
private final Map<NodeId, Fiber> nodes = new HashMap<NodeId, Node>();
}
which poses a big problem if my use case is just to edit the location or the name of the Network
. In that case I just don't care about fibers and nodes and realistically, it is expected them to be quite possible for their numbers to be on the order of 10k-100k nodes/fibers!
How should I approach this issue? Should I separate the definition of a Network
(containing fibers
and nodes
and their invariants) from the rest of the fields?
I've always thought of Aggregate Roots as Entities that have a set of invariants to hold over its attributes, in contrast with Entities that just don't care abouts the state of their attributes (for instance, a Person defined with a name and age wouldn't probably need to have any kind of checking for invalid combinations of name and age).
Following this philosophy, I generally tend to decide whether some domain concept is either a Value, Entity, Value or Event and then if it's an Entity, if it's an Aggregate Root. Is my assumption flawed?
Thanks
Upvotes: 0
Views: 316
Reputation: 16358
First of all, don't waste time thinking which is an entity or value objects. Technical details like this come up by themselves. The important thing is to model correctly the concepts. So, what does the domain understand by Network? Is it the container of Nodes or Fibes or itself a logical unit?
Can you have a network without any Node or Fibe? Can an empty Network exists in the domain? Does the Network contains Node and Fibe or the Node and Fibe are organized (grouped by) in a Network? You have to determine if a collection of Node or Fibe really define a network i.e you simply can't have a valid Network concept without those concepts.
Also it does matter the bounded context, the Network concept is specific to one context, it might look a bit different in other context. There is no one single Model valid everywhere. So, in what context are you defining the Network? You need to define only things relevant to THAT context not everything that might be part of Network at some point.
Don't do DDD as a recipe, looking for technical patterns to identify an aggregate root (AR). Do it organically, just try to design the model according to the specific domain context. You'll know when something is an AR not only an entity.
As a thumb rule, an AR is not a container it's still a domain concept which happens to act as a facade for other related concepts.
Upvotes: 3
Reputation: 7283
What about delegate the invariant protection to smaller aggregate root?
1.both ends of any fiber are connected to a Node;
2.that no two ends are connected to the same Node;
I think these two could be protected by Fiber. While this one below is kind of tricky, a simple solution is to use database constraint on the location.
3.that no two nodes can be in the same (x, y) location.
Then the network is just an aggregate root with identity and some information.
Upvotes: 1