I'm looking to refactor an existing design; to move a bunch of stuff out of a database and into memory where it should be (There are many reasons the DB approch is dangerous as it is now). My first act was to take all the existing objects and expand more state to them. The previous objects new only their parents, and that was it. From the youngest child you could walk up to find parents, but you couldn't ask "what edges are on this node" at all.
I changed things to make state more accessible from every object. Now each object effectively knows of it's parent and all of it's children. I thought this was an obvious simplification that would make storing things in memory much easier. The problem is that I need to be able to construct objects without modifying my model, untill addToModel is called, which means I need to be able to construct objects in one state, and then update some of their state to be consistent with the Model's state and properly represent all the interconnectivity (node has to be informed when an edge is added, edge needs to know it's paths etc etc).
This proved surprisingly complicated to keep consistent. I end up with either encapsulation issues (like assuming each object knows not to call the package scope methods that change memory from public methods that shouldn't be able to change state), as well as a concern about aliasing (what if someone creates a new Node A with no connections, when my Model says node A should be connected to B, C, and E?). I thought of many approches that work, but none feel 'clean'. Is the issue that I"m trying to make my objects too aware of state, and thus putting too much effort on my model to maintain this state?