Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > In search of an Elegent Design Pattern for this problem

Reply
Thread Tools

In search of an Elegent Design Pattern for this problem

 
 
S. Jacobs
Guest
Posts: n/a
 
      11-21-2003
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
 
Reply With Quote
 
 
 
 
Filip Larsen
Guest
Posts: n/a
 
      11-21-2003
"S. Jacobs" wrote

> 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,
--
Filip Larsen


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ and design Pattern (Composite design Pattern ) Pallav singh C++ 1 01-22-2012 10:48 PM
C++ and design Pattern (Composite design Pattern ) Pallav singh C++ 0 01-22-2012 10:26 PM
C++ and design Pattern (Composite design Pattern ) Pallav singh C++ 0 01-22-2012 10:25 PM
May I have a example of design pattern of "composite", I still feel fuzzy after reading book of Addison-Wesley's"design pattern " jones9413@yahoo.com C++ 1 08-31-2007 04:09 AM
Elegent solution to replacing ' and " ? fyleow Python 3 05-06-2006 08:24 PM



Advertisments