1/38
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
What are structural design patterns concerned with?
How classes and objects are composed into larger structures.
What are the two broad types of structural patterns?
Class structural and object structural.
What pattern is the focus of this deck?
Adapter.
What problem does the Adapter pattern solve?
It lets classes work together when their interfaces are incompatible.
What is the definition of Adapter?
Adapter converts the interface of a class into another interface clients expect.
When should Adapter be used?
When you want to use an existing class but its interface does not match what the client needs.
In the DVR example, what is the main issue?
Different DVR manufacturers provide different interfaces for similar operations.
What are the three DVR libraries in the slides?
CiscoDvr, SonyDvr, and TivoDvr.
Why is the giant if/else solution bad?
Because client code becomes messy and tightly coupled to concrete DVR implementations.
What is the Target in the Adapter pattern?
The interface the client expects.
What is the Adaptee in the Adapter pattern?
The existing class with the incompatible interface.
What is the Adapter in the Adapter pattern?
The class that translates between the Target and the Adaptee.
What is the common target interface in the slides?
Dvr.
What methods does the Dvr interface provide?
play(h, m, s), stop(), and pause().
What adapter classes are shown in the slides?
CiscoDvrAdapter, SonyDvrAdapter, and TivoDvrAdapter.
What does CiscoDvrAdapter::play do?
It converts h/m/s into a Time object and calls beginPlayBack.
What does SonyDvrAdapter::play do?
It converts h/m/s into total seconds and calls startPlayback(seconds).
What does TivoDvrAdapter::play do?
It forwards the values directly to playFrom(h, m, s).
Why is Adapter useful in the DVR example?
It lets the same client code work with Cisco, Sony, or Tivo DVRs through one common interface.
What does the client code interact with after adaptation?
The Target interface, not the concrete adaptee classes.
What is a class adapter?
An adapter that uses inheritance.
What is an object adapter?
An adapter that uses composition.
What does the deck’s class adapter inherit from publicly?
The target interface Dvr.
What does the deck’s class adapter inherit from privately?
The concrete adaptee class.
What is one advantage of class adapter?
Only one object is involved and there is no extra pointer indirection.
What is one disadvantage of class adapter?
It is tied to a specific adaptee class.
What is one advantage of object adapter?
It can work with an adaptee and its subclasses.
What is one disadvantage of object adapter?
It is harder to override adaptee behavior.
What is the key exam phrase for Adapter?
Convert one interface into another interface the client expects.
What is a simple memory trick for Adapter?
Target is what the client wants, Adaptee is what you have, Adapter is the translator.