This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Converting bidirectional object graph to unidirectional Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Converting bidirectional object graph to unidirectional" Watch "Converting bidirectional object graph to unidirectional" New topic
Author

Converting bidirectional object graph to unidirectional

Luigi Smith
Ranch Hand

Joined: Nov 08, 2003
Posts: 54
I've been giving some thought on how I might implement the following scenario:

Object Foo
----------
Set barsSet
String names

Object Bar
----------
Object Foo
Set farsSet
String projects

Object Far
----------
Object Bar

As you can see the cardinality between Foo and Bar is one-to-many and is bidirectional and so forth on to object Far (my life example is a much extensive object graph). What I want to do is make this graph unidirectional by removing Object Foo from Object Bar and Object Bar from Object Far and so on.

I am using Java so I have been thinking about a generic solution that could use reflection (since I know I can traverse the graph using everything that ends in "Set"), and I could use cloning to create identical objects but without the relationships back or maybe BeanUtils to copy the bidirectional version of the object into a unidirectional version without the link back.

I've been considering using a pattern as well to solve this, but not sure if I should use Builder or some other creational pattern since this is that type of issue. Any suggestions would be appreciated.

Thanks!


Luigi<br />------------<br />Sun Certified Java Programmer<br />IBM Certified Enterprise Developer WSAD 5.0
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Converting bidirectional object graph to unidirectional
 
Similar Threads
java does not support multiple inheritance. Is it a limitation to java?
Using final as program-wide variables
EJB unidirectional CMR
Convert bi-directional object graph to uni-directional
Garbage Collection!