SlideServe
Menu
Préférences
© SlideServe · v2026

Adapter

molmos avatar
14 diapositives · 211 Views · Jan 07, 2020

Adapter. Adapter. Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces. Aka: Wrapper. Motivation.

Adapter - slide 1
01 / 14Adapter
1 / 17

Télécharger la présentation

Adapter
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. Adapter

  2. Adapter • Convert the interface of a class into another interface clients expect. • Adapter lets classes work together that couldn't otherwise because of incompatible interfaces. • Aka: Wrapper

  3. Motivation • Sometimes a toolkit class designed for reuse isn't reusable only because its interface doesn't match the domain-specific interface an application requires.

  4. Adapter Solution

  5. Possible Adapter Structures

  6. Participants • Target (Shape) • defines the domain-specific interface that Client uses. • Client (DrawingEditor) • collaborates with objects conforming to the Target interface. • Adaptee (TextView) • defines an existing interface that needs adapting. • Adapter (TextShape) • adapts the interface of Adaptee to the Target interface.

  7. Collaborations • Clients call operations on an Adapter instance. In turn, the adapter calls Adaptee operations that carry out the request.

  8. About Identity • A decorator and its component aren't identical. • A decorator acts as a transparent enclosure. But from an object identity point of view, a decorated component is not identical to the component itself. • If the decorator is wrapping, then identity of the object may change. • Good at construction time, but else should “adapt” the references from the decorated to the decorator.

  9. Consequences • More flexibility than static inheritance. Dynamic addition of properties • Avoids feature-laden classes high up in the hierarchy. • Lots of little objects.

  10. Implementation • Interface conformance. A decorator object's interface must conform to the interface of the component it decorates. ConcreteDecorator classes must therefore inherit from a common class (at least in C++). • Omitting the abstract Decorator class. There's no need to define an abstract Decorator class when you only need to add one responsibility. • Keeping Component classes lightweight. Component should specify an interface, decorators are then easier to define

  11. Wrapping or not? Conforming or not • With decorator • With strategies

  12. Strategies? • Strategies are a better choice when the Component class is heavyweight, thereby making the Decorator pattern too costly to apply. • The Strategy-based approach might require modifying the component to accommodate new extensions. • - a strategy can have its own specialized interface, • - a decorator's interface must conform to the component's. • A strategy needs only define the interface for rendering a border, which means that the strategy can be lightweight even if the Component class is heavyweight.

  13. Known Uses • VisualWorks Wrapper hierarchy • Stream Decorators in VisualWorks: • BOSSTransporter is a stream decorator • FormattedStream is a stream decorator