Week 15 Class 28 Thu Apr 22 Posted: Apr 22

Class session:

  1. Announcements
  1. Screencast: Design Pattern: Composite notes
  2. Exercise 74: Design Pattern: Composite Crossword
  3. Screencast: C++ Constructor Specifiers notes
  4. Exercise 75: C++ Constructor Specifiers Crossword
  5. Screencast: Design Pattern: Adapter notes
  6. Exercise 76: Design Pattern: Adapter Crossword

    The design pattern Adapter has two forms, a class adapter and an object adapter. The class adapter gets access to the adaptee using inheritance:

    The object adapter gets access to the adaptee using delegation:

    In delegation, we keep a data member of the target class. E.g., the class Adapter has a data member adaptee of type Adaptee. Then, when we want to use the adaptee, we call the adaptee’s methods.

    The notes suggest for C++ preferring an object adapter (which uses delegation) over a class adapter (which uses inheritance). This preference is an example of the application of the Fowler refactoring “Replace Inheritance with Delegation”. The creators of design patterns realized later that some design patterns favored inheritance when delegation leads to a cleaner design.

Screencast Folder: Class 28 Thu Apr 22

Exercise Due Date: 4 pm on Friday, Apr 23

Reminders: