Structural patterns Adapter Bridge Composite R Decorator Facade Flyweight k Proxy
Structural Patterns • Adapter • Bridge • Composite • * Decorator • Facade • Flyweight • * Proxy
模式7: Adapter(-) Aliases: Wrapper Intent Convert the interface of a class into another inter face clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces Motivation Sometimes a toolkit class that's designed for reuse isn't reusable only because its interface doesn't match the domain-specific inter face an application requires
模式 7: Adapter (一) • Aliases:Wrapper • Intent – Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces. • Motivation – Sometimes a toolkit class that's designed for reuse isn't reusable only because its interface doesn't match the domain-specific interface an application requires
Adapter模式(二) Applicability: Use the Adapter pattern when you want to use an existing class, and its interface does not match the one you need you want to create a reusable class that cooperates with unrelated or unforeseen classes. that is. classes that don't necessarily have compatible interfaces (object adapter only) you need to use several existing subclasses, but it's impractical to adapt their interface by subclassing every one. An object adapter can adapt the interface of its parent class
Adapter模式(二) • Applicability:Use the Adapter pattern when – you want to use an existing class, and its interface does not match the one you need. – you want to create a reusable class that cooperates with unrelated or unforeseen classes, that is, classes that don't necessarily have compatible interfaces. – (object adapter only) you need to use several existing subclasses, but it's impractical to adapt their interface by subclassing every one. An object adapter can adapt the interface of its parent class
Adapter模式( Struct class Client Target Adaptee Request( SpecificRequesto) adapter (impl Adapter Request(o- SpecificRequest() object Client Target Adaptee Request( Specific Request adapter adaptee Adapter Request()o卜- adaptee->SpecificRequesto
Adapter模式(三) • Struct class adapter object adapter
Adapter模式(三) ° Participant Client、 Target、 Adaptee、 Adapter Collaborations class adapter-delegation obJect adapter container
Adapter模式(三) • Participants – Client、Target、Adaptee、Adapter • Collaborations – class adapter —— delegation – object adapter —— container