Search code examples
oopdesign-patternsooad

Should Interface implementations be independent


I have come across some legacy code that has raised all my heckles as an Object Oriented Programmer.

Here's the pattern used often: An interface has two implementations and one implementation calls a method of the other.

Now, I think it should be refactored so that the implementations do not know about each other. It is simple enough HOW to do it. What I cannot figure out clearly - & hoping good people of SO would help me with - is WHY.

I can see the theoratical reason - it is a terrible object-oriented design. But I am playing the devil's advocate here and asking - what is the practical disadvantage of two implementation having knowledge of each other. Why should time & money be spent to get rid of this (in my mind) anti-pattern?

Any info or links on this will be appreciated.


Solution

  • There is nothing wrong with an implementation1 of interface1 being aware of or interacting with implementation2 of interface1.

    I think you have just spotted an intended or un intended implementation of proxy pattern http://en.wikipedia.org/wiki/Proxy_pattern

    Hope this helps :)