Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Bi-directional navigation and circular dependancy  RSS feed

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this confusion. When objects of two classes A and B can call each other's methods, the relationship is bidirectional, right? Now to implement these A and B classes, A has to know about B and B has to know about A, so compilation is a problem. OK, one can get around compilation problem using reflection.
The real question I have is if circular dependancy is bad and implementing bidirectional relationship requires it, then bidirectional relation is bad? I am sure I am missing something because bi-directional relationship is quite common.

We have a scenario where facade builds the cache (a singleton), and inside those cache building methods there calls to facade to get data.
Is something wrong with this design?
Any help is very much appreciated.
-Roshan
 
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wouldn't say that it's *wrong* per se - just somewhat "smelly".
You might want to take a look at the practice ofDependency Inversion, though...
 
Roshan Lal
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ilja. I too feel it is smelly. Thanks for the URL, I will go there.

Originally posted by Ilja Preuss:
I wouldn't say that it's *wrong* per se - just somewhat "smelly".
You might want to take a look at the practice ofDependency Inversion, though...

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!