Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 12
Software Design and Architecture
Structural Design Patterns
Adapter Intent Convert the interface of a class into another interface that clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces. Also Known As Wrapper Adapter Motivation Problem: Suppose your cell phone has a 110 volt power feed. In your country, you have 220 volt system feed Solution: Design an adapter, i.e. a transformer, that will convert 220 volts to 110 volt interface of your cell phone. Target: 110 volts system Adaptee: 220 volts system Adapter: Transformer 220 to 110 In software engineering, the adapter pattern is a software design pattern that allows the interface of an existing class to used from another interface. It is often used to make existing classes work with others without modifying their source code. Adapter Applicability Use Adapter design pattern when… You want to use an existing class, and its
interface does not match the one you need.
Adapter Structure A class adapter uses multiple inheritance to adapt one interface to another Adapter Object Adapter An object adapter relies on object composition Adapter Participants Target (110 volt system) Defines the domain-specific interface that Client uses. Client (User) Collaborates with objects conforming to the Target interface. Adaptee (220 volt system) Defines an existing interface that needs adapting. Adapter (Transformer) Adapts the interface of Adaptee to the Target interface. Adapter Collaborations Clients call operations on an Adapter instance. In return, the adapter calls Adaptee operations that carry out the request. Adapter Consequences (Class Adapter) Pros Less code required than the object Adapter Can override Adaptee’s behavior as required Cons Required sub-classing (tough for single inheritance) Less Flexible Adapter Consequences (Object Adapter) Pros Doesn’t require sub-classing to work More Flexible Cons Harder to override Adaptee behavior Requires more code to implement properly The End Thanks for listening Questions would be appreciated…