1

If you look at the wikipedia bridge entry there is an inconsistency in that the UML diagram depicts the implementor as a private variable, yet the accompanying Java code example has it as non-private and the refined abstraction makes use of it as in the following code fragment:

 // low-level i.e. Implementation specific
   public void draw() {
        drawingAPI.drawCircle(x, y, radius);
   }

the drawingAPI is the implementor and is accessed from the refined abstraction.

Also in the same wikipedia entry the LePUS3 diagram implies that the refined abstractions should only call operations from the abstraction and not any methods from the implementor.

See also the following stackoverflow answer where the implementor is private: https://stackoverflow.com/a/319792/480894

So should the implementor be private and refined abstractions only call methods from the abstraction?

Community
  • 1
  • 1
Roland
  • 7,525
  • 13
  • 61
  • 124

1 Answers1

1

You are correct about the contradiction between the diagram and the java code example. Nevertheless to answer your question, the diagram shows you the purist way (preferred) to implement the pattern.

Still implementing the pattern as seen in the example doesn't break the usefulness of the pattern. It doesn't break encapsulation nor inheritance.

One advantage of using a private member and forwarding calls only through the base ( the Abstraction ) is that you can enforce additional behavior in the base class, for instance you can log the calls or you can perform whatever operation you wish. This will reduce duplication in the subclass.

Ibrahim Najjar
  • 19,178
  • 4
  • 69
  • 95