File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Murach's Java Servlets and JSP this week in the Servlets 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
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Converting bidirectional object graph to unidirectional
 
Similar Threads
EJB unidirectional CMR
Convert bi-directional object graph to uni-directional
Using final as program-wide variables
java does not support multiple inheritance. Is it a limitation to java?
Garbage Collection!