chapter ten

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 may 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 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 outside of our control. Our example application must generate a report about the attendance and venue of various school sports, but each sport reports 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.

10.1 The Adapter Design Pattern integrates code

10.1.1 Desired design features

10.1.2 Before using Adapter

10.1.3 After using Adapter

10.1.4 Adapter’s generic model

10.1.5 An alternative Adapter model

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

10.2.1 Desired design features

10.2.2 Before using Façade

10.2.3 After using Façade

10.2.4 Façade’s generic model

10.3 Choosing between Adapter and Façade

Summary