1 / 19

Broker Design Patterns: Adapters and Proxy

Broker Design Patterns: Adapters and Proxy. Objectives. To introduce Class and Object Adapter patterns and discuss their use To introduce the Proxy patterns and discuss its use. Topics. The Adapter/Wrapper patterns The Proxy pattern. The Adapter/Wrapper Patterns.

Download Presentation

Broker Design Patterns: Adapters and Proxy

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Broker Design Patterns: Adapters and Proxy

  2. Objectives • To introduce Class and Object Adapter patterns and discuss their use • To introduce the Proxy patterns and discuss its use

  3. Topics • The Adapter/Wrapper patterns • The Proxy pattern

  4. The Adapter/Wrapper Patterns • Often a component has reusable function but not a usable interface. • An adapter or wrapper is a component that provides a new interface to an existing component. • Analogy: electrical or plumbing adapters

  5. Class and Object Adapters An adaptee may be given a new interface by an adapter in two ways: • Inheritance—The adapter may sub-class the adaptee; this is the Class Adapter pattern • Delegation—The adapter may hold a reference to the adaptee and delegate work to it; this is the Object Adapter pattern

  6. Class Adapter Structure

  7. Object Adapter Structure

  8. Object Adapter Behavior

  9. Example: A Thread-Safe Priority Queue—Problem PriorityQueue works properly but is not thread-safe—how can we reuse this class in a thread-safe way?

  10. Example: A Thread-Safe Priority Queue—Class Adapter

  11. Example: A Thread-Safe Priority Queue—Object Adapter

  12. More Adapter Examples • Adding an adapter to a text editing class to make it resemble the members of a shape editing class in a graphical editor • Adding a class interface to fundamental data types that have atomic values (as in Java) • Wrapping legacy code to provide an OO interface

  13. When to Use Adapters • The current context of use expects a certain interface. • A simplified interface is needed. • Operations with slightly different functionality are needed.

  14. The Proxy Pattern • Stand-ins for object may be needed because the real object • Is not locally available; • Is expensive to create; or • Needs protected access for security or safety. • The stand-in must • Have the same interface as the real object; • Handle as many messages as it can; • Delegate messages to the real object when necessary. • Analogy: a stand-in or proxy

  15. Proxy Pattern Structure

  16. Proxy Pattern Behavior

  17. Example: Image Proxy

  18. When to Use Proxies • Use the Proxy pattern whenever the services provided by a supplier need to be mediated or managed in some way without disturbing the supplier interface. • Kinds of proxies: • Virtualproxy—Delay the creation or loading of large or computationally expensive objects • Remoteproxy—Hide the fact that an object is not local • Protectionproxy—Ensure that only authorized clients access a supplier in legitimate ways

  19. Summary • The Adapter patterns use inheritance (Class Adapter) or delegation (Object Adapter) to change the interface of an existing component for reuse. • The Proxy pattern provides a stand-in for a real object that mediates interaction with a client without disturbing its interface.

More Related