0% found this document useful (0 votes)
26 views16 pages

Component Engineering - Adapter Proxy

This document discusses the adapter and proxy design patterns. The adapter pattern allows classes with incompatible interfaces to work together by wrapping its interface for a client class. It discusses class and object adapters. The proxy pattern provides a placeholder for another object to control access to it. It can be used for remote object access or lazy initialization. Examples of each pattern are provided.

Uploaded by

Arijit Maji
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views16 pages

Component Engineering - Adapter Proxy

This document discusses the adapter and proxy design patterns. The adapter pattern allows classes with incompatible interfaces to work together by wrapping its interface for a client class. It discusses class and object adapters. The proxy pattern provides a placeholder for another object to control access to it. It can be used for remote object access or lazy initialization. Examples of each pattern are provided.

Uploaded by

Arijit Maji
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Introduction to Design Patterns

Adapter and Proxy

Santanu Sinha

Problem 1: Container to Queue

We have a custom container interface present in the library The container provides methods to add/remove objects from the beginning and end It also provides lots of other functionality such as efficient searching, insertion in the middle etc. We want customer to have a queue

Santanu Sinha

Problem 2: Container to Queue

We have a custom container interface present in the library The interface has been sub-classed into different implementations One of these implementations are selected by the library depending on some parameters We want customer to have a queue

Santanu Sinha

Adapter / Wrapper

Provides compatible interfaces to unforseen use-case scenarios

Santanu Sinha

Object Adapter

Adapts a hierarchy of objects

Santanu Sinha

Adapter: Consequences

Class Adapter:

Commits to adapt a particular class Can override functionality of adaptee No pointer redirection required Cannot adapt subclasses of a class Can adapt many classes at once Cannot override adaptee functionality Pointer dereferencing required
Santanu Sinha

Object Adapter

Example

Santanu Sinha

Adapter: Implementation issues


How much to adapt Pluggable adapters for frameworks


Using abstract functions Using delegate objects

Generic Adapters

Santanu Sinha

Pluggable Adapter: Abstract methods

Santanu Sinha

Plugable Adapter: Delegate object

Santanu Sinha

Problem 3: Logging

Remote logging is required For production use, logging is required only in error case Log object initialization will take some time We want to defer creation of this object as long as possible

Santanu Sinha

Proxy / Surrogate

Provide a place-holder for another object to control access to it

Santanu Sinha

Proxy: Consequences

A proxy for remote object can be efficient On demand object creation may be possible Can be used to perform house-keeping tasks

Santanu Sinha

Example

Santanu Sinha

Proxy: Implementation Issues

Create pointer type with overloaded operator -> and operator * Proxy can be improvised to point to any class in an inheritance hierarchy

Santanu Sinha

Conclusion

Questions?

Santanu Sinha

You might also like