I am looking for a design pattern to gracefully build relation between objects. one->many and one-one.
but make the objects standalone as well.
For example I have
Customer object....this customer object can containt many Contracts objects. One contract object can have one Product object because contract is made on per product bases...if you want to buy more products..you make more contracts. (thats just business rulz)
So right now..what I am doing is I search for any creterea for example contract_id and I find to which customer_id it belongs.
Then I build customer object....build contract objects within it in private $contracts = array() property.... and so on ...
I end up having one/many customer objects with contract objects within...wich in their turn magically contains one-to-one relation to product objects.
So my question is how is the right approach to build this relation and still be able to take contracts as separate thing for example. Because as separat entities they make perfect sense.
I was thinking maybe on creation of an object (using factory or whatever) I add the relative object in a container for contact, contracts etc. But then I kind of not sure how to make for example : relation between given contract and to which contact it belongs.
To much talk...hopefully this all makes some sense.