• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Converting bidirectional object graph to unidirectional

 
Luigi Smith
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic