Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Converting bidirectional object graph to unidirectional

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.

    Bookmark Topic Watch Topic
  • New Topic