In search of an Elegent Design Pattern for this problem

S

S. Jacobs

I'm trying to come up with an elegent design to solve this problem and
wondered if anyone had any ideas. Here is the problem:

Object A - parent object

Object B - child object in a many to one relationship with parent

Object B inherits all the properties and values from object A

Object A can change a value to any property and the change should be
inherited from Object B

Object B can change any value of the property inherited from Object A.
The change should NOT be propogated to any siblings or to Object A.

Example:

Object A:
String test = "objectA"

Object B1:
the value of test = "objectA"

Object B2:
the value of test = "objectA"

Action: Object B1 changes the value of test to "objectB"

Result:
The value of A.test is "objectA"
The value of B1.test is "objectB"
The value of B2.test is "objectA"

Action: Object A changes the value of test to "objectAAA"

The user can choose whether to propogate the change to the child
objects. The user chooses Yes, to propogate the objects.

Results:
The value of A.test is "objectAAA"
The value of B1.test is "objectAAA"
The value of B2.test is "objectAAA"


I'm looking for an elegent solution other than the obvious one of
simply creating 3 identicle objects and copying all the data to all
objects. I'm hoping to find one that is efficient in both object
creation and data storage.

Hope this makes sense! Any and all suggestions are welcome
 
F

Filip Larsen

Action: Object B1 changes the value of test to "objectB"

Result:
The value of A.test is "objectA"
The value of B1.test is "objectB"
The value of B2.test is "objectA"

Action: Object A changes the value of test to "objectAAA"

The user can choose whether to propogate the change to the child
objects. The user chooses Yes, to propogate the objects.

Results:
The value of A.test is "objectAAA"
The value of B1.test is "objectAAA"
The value of B2.test is "objectAAA"

I'm looking for an elegent solution other than the obvious one of
simply creating 3 identicle objects and copying all the data to all
objects. I'm hoping to find one that is efficient in both object
creation and data storage.

Except for the optional propagation part, it sounds close to what a Map
with parent functionality can do, like javax.swing.ActionMap and others.
Perhaps you can find some inspiration there.


Regards,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top