Connectors: A Design Pattern for Maintaining Consistent Object Relationships
The entities in an application's domain model are defined in large part by their relationships between them. The basic three are one-to-one, one-to-many, and many-to-many, but additional invariants may be layered on top of these. In a traditional OOP style, entities are responsible for maintaining these invariants, via logic in their public mutator methods. I propose an alternative that I call the connector pattern. In the connector pattern, object relationships are created and destroyed (connected and disconnected) by a third object called a Connector.
While objects should be responsible for maintaining their own local invariants, relationships are not local. They encompass both objects involved in a relationship. As a result, mutator methods on both objects must enforce a shared invariant. If a Foo has many Bars, then
Bar.setFoo(Foo) should be equivalent operations. These two meth