CS计算机代考程序代写 COMP2511

COMP2511

Adapter Pattern

Prepared by
Dr. Ashesh Mahidadia

Adapter Pattern : Intent

v “Convert the interface of a class into another interface clients expect.
Adapter lets classes work together that couldn’t otherwise because of incompatible
interfaces.” [GoF]

v The adapter pattern allows the interface of an existing class to be used as another
interface, suitable for a client class.

v The adapter pattern is often used to make existing classes (APIs) work with a client class
without modifying their source code.

v The adapter class maps / joins functionality of two different types / interfaces.

v The adapter patter offers a wrapper around an existing useful class, such that a client
class can use functionality of the existing class.

v The adapter pattern do not offer additional functionality.

COMP2511: Decorator and Adapter Patterns 2

Adapter Pattern: Structure

v The adapter contains an instance of the class it wraps.
v In this situation, the adapter makes calls to the instance of the wrapped object.

COMP2511: Decorator and Adapter Patterns 3

Adapter: Example

COMP2511: Decorator and Adapter Patterns 4

COMP2511: Decorator and Adapter Patterns 5

Adapter: Example

Design Patterns: Discuss Differences

vCreational Patterns
v Abstract Factory
v Factory Method
v Singleton

vStructural Patterns
v Adapter
v Composite
v Decorator

COMP2511: Decorator and Adapter Patterns 6

vBehavioral Patterns
v Iterator
v Observer
v State
v Strategy
v Template
v Visitor

discussed

discussed

discussed

discussed

discussed

discussed

discussed

We plan to discus
s the rest of the d

esign

patterns above in
the following wee

ks; and

many more other
topics.

End

COMP2511: Decorator and Adapter Patterns 7