A Network
is composed of Node
s that are connected with Fiber
s. The Network
is responsible for making sure that:
- both ends of any fiber are connected to a
Node
; - that no two ends are connected to the same
Node
; - that no two nodes can be in the same (x, y) location;
- a network has a limit of 10 nodes and 10 fibers.
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