Hye!
I have Aggregate object that have more than one level. Aggregate root is Network object and it have collection of Nodes and Links. Node and Link have collection of Segments, and Segment have collection of Lanes. My domain is traffic network and this is only part of this aggregate:
public class Network
{
private List<Node> nodes;
private List<Link> links;
}
public class Node
{
private Segment segment;
}
public class Link
{
private List<Segment> segments;
}
public class Segment
{
private List<Lane> lanes;
}
public class Lane
{
private List<Cell> cells;
}
public class Cell
{
private bool IsOccupied;
}
First of all, can somebody tell me is this good or it's better to breakdown this aggregate on maybe three levels (Network, Segment, Cell) with repository pattern implemented on top of that roots.
My problem is with additional functionality that i want to add to network. If this network is going to be used for simulation then simulator need vehicle sources and sinks that will generate and destroy vehicles on the edge of network. My idea is to have that functionality out of network aggregate. This is the code:
public class Simulation
{
public void Iteration()
{
//do something with vehicles
//foreach sink in sinkRepository call o.Update()
}
}
public class SinkRepository
{
private List<Sink> sinks;
//Singleton pattern
//+ CRUD operations and GetEnumerator()
}
public class Sink
{
private int nodeId;
private List<int> laneIds;
public void Update()
{
//need reference to Network object
//foreach laneId
////network.GetLane(id)
////find is cell in lane occupied
////if it is then network.SetCellStatus(false);
}
}
Is this good way to do it? And what are your suggestions :) Also i have some persistance code that create network from XML, and it can also create sinks from XML but the problem is how to elegante pass reference of Network object to sink object because sink object needs reference to network because it need to fetch lane based on laneId.
I was thinking about adding repository of network and repository would be singleton so sink would see it witout keeping reference on network throw whole lifetime.