10 The Adapter and Façade Design Patterns

 

This chapter covers

  • The Adapter Design Pattern
  • The Façade Design Pattern

In this chapter, we tackle an all-too-common problem: working with legacy software. This code can be from a library that we can’t modify, or it can be other external code that we don’t have access to or otherwise cannot modify.

The Adapter Design Pattern provides a model for a software architecture that needs to integrate external code, such as from a library, with code in an existing application. However, the external and application codes weren’t originally designed to work together, and we cannot change either of them. The pattern can also help to isolate an application from interface changes in the external code that may be beyond our control. Our example application must generate a report about the attendance and venue of various school sports, but the sports report that data differently.

The Façade Design Pattern provides a simpler higher-level interface that makes complex code that we can’t modify easier to use. Our example application must interact with multiple organizations to raise funds for school sports.

NOTE

Be sure to read the introduction to part 4 for important information about design patterns in general and to learn how this and subsequent chapters teach each pattern.

10.1 The Adapter Design Pattern integrates code

10.1.1 Desired design features

10.1.2 Before using the Adapter Design Pattern

10.1.3 After using the Adapter Design Pattern

10.1.4 Adapter’s generic model

10.1.5 An alternative Adapter Design Pattern model

10.2 The Façade Design Pattern hides a subsystem of interfaces

10.2.1 Desired design features

10.2.2 Before using the Façade Design Pattern

10.2.3 After using the Façade Design Pattern

10.2.4 Façade’s generic model

Summary