Class adapter pattern in the classic TimedDoor case study

59 Views Asked by At

In Uncle Bob's classic tutorial on ISP, he presents a case study on a timed security door. Martin suggests two possible designs for combining the TimerClient with the Door hierarchy:

An Object Adapter pattern: Object adaper

A Class Adapter pattern: Class adapter

My question is how to interpret the Class Adapter. Who is the adapted interface, who is the adapter and who is the adaptee? There are two options that can I think of:

  • The Door is the adaptee, and the TimedDoor is the adapter. This conforms with the structure of the Class Adapter pattern, as the adapter inherits from the two abstract classes.
  • The TimedDoor is both the adapter and adaptee. This is consistent with the Object adapter solution, with a "shortcut", combining the adapter and adaptee together.

Can you clarify this point?

1

There are 1 best solutions below

0
jaco0646 On

The UML diagrams from page 141 of the GoF book include appropriate labels.

GoF page 141

So your first bullet is closer: the Target is whichever interface the Client knows and uses; the Adaptee is whichever interface gets called by the Adapter. If the Client knows and uses both interfaces, you can have a two-way Adapter where Target and Adaptee are interchangeable.