CSC/ECE 517 Fall 2012/ch2b 2w47 am: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
Line 25: Line 25:
= Directory of sites =
= Directory of sites =


* [http://en.wikipedia.org/wiki/Adapter_pattern Adapter Pattern on wikipedia]
=== [http://en.wikipedia.org/wiki/Adapter_pattern Adapter Pattern on wikipedia] ===
<b>Topics Covered:</b><br>Lists various structures of Adapter Pattern viz., Object Adapter Pattern, Class Adapter Pattern, Runtime Adapter pattern and implementation of Adapter pattern. It provides a few examples for the above structures.
 
<b>Summary:<b><br>In computer programming, the adapter pattern (often referred to as the wrapper pattern or simply a wrapper) is a design pattern that translates one interface for a class into a compatible interface. The adapter is also responsible for transforming data into appropriate forms. For instance, if multiple boolean values are stored as a single integer (i.e. flags) but your client requires a 'true'/'false', the adapter would be responsible for extracting the appropriate values from the integer value. Another example is transforming the format of dates (e.g. YYYYMMDD to MM/DD/YYYY or DD/MM/YYYY).<br><br>
* Object Adapter pattern:<br>
In this type of adapter pattern, the adapter contains an instance of the class it wraps. In this situation, the adapter makes calls to the instance of the wrapped object.<br>
* Class Adapter pattern:<br>
This type of adapter uses multiple polymorphic interfaces to achieve its goal. The adapter is created by implementing or inheriting both the interface that is expected and the interface that is pre-existing.<br>
* A further form of runtime Adapter pattern:<br>
This section provides a good example for runtime Adapter pattern.<br><br>
* Implementation:<br>
Provides a basic skeleton of how to implement the adapter pattern.
<br>
<b>Pros:</b> This wikipedia page works if readers want a quick review of the adapter pattern. Also it provides good references to read more about the Adapter pattern.
<b>Cons:</b> It doesn't helps to understand the Adapter pattern in depth. The examples provided are not easy to comprehend ( unless you are an experienced programmer and not a beginner! ). Its not a good page to refer for the beginners.

Revision as of 05:44, 18 November 2012

Adapter Pattern, a directory of sites

This wiki page provides a directory of sites for Adapter Design Pattern that will help readers to know what each website contains, why should readers refer one website over another and a list of examples that readers can look up to understand the Adapter Pattern.

Introduction

Sometimes, objects just don't fit together as they should. A class may have changed, or an object turns out to be just too difficult to work with. At such times, adapter design pattern comes to the rescue. Adapter pattern lets you adapt what an object or class has to offer so that another object or class can make use of it. It also helps when classes can't work together because of incompatible interfaces.

Since we are huge fans of visual approach, lets understand the adapter pattern with the help of a diagram. Hold on! Before going in to the UML diagram ( which is kind of less attractive, right? May be .. ) lets look at the figure below which is more appealing.


A real world example for the Adapter Pattern.




The above example helps readers quickly get across the intent of the pattern than the UML diagram shown below. Looking at the UML diagram now, can help the readers to learn about the precise relationships between the classes in adapter pattern and it makes a lot more sense!


UML diagram for the Adapter Pattern.




So, this is all what we had to talk about Adapter Pattern. Lets look at other websites and see what they say about Adapter pattern, (which is probably, the main purpose of the wiki page).

Directory of sites

Adapter Pattern on wikipedia

Topics Covered:
Lists various structures of Adapter Pattern viz., Object Adapter Pattern, Class Adapter Pattern, Runtime Adapter pattern and implementation of Adapter pattern. It provides a few examples for the above structures.

Summary:
In computer programming, the adapter pattern (often referred to as the wrapper pattern or simply a wrapper) is a design pattern that translates one interface for a class into a compatible interface. The adapter is also responsible for transforming data into appropriate forms. For instance, if multiple boolean values are stored as a single integer (i.e. flags) but your client requires a 'true'/'false', the adapter would be responsible for extracting the appropriate values from the integer value. Another example is transforming the format of dates (e.g. YYYYMMDD to MM/DD/YYYY or DD/MM/YYYY).

  • Object Adapter pattern:

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

  • Class Adapter pattern:

This type of adapter uses multiple polymorphic interfaces to achieve its goal. The adapter is created by implementing or inheriting both the interface that is expected and the interface that is pre-existing.

  • A further form of runtime Adapter pattern:

This section provides a good example for runtime Adapter pattern.

  • Implementation:

Provides a basic skeleton of how to implement the adapter pattern.
Pros: This wikipedia page works if readers want a quick review of the adapter pattern. Also it provides good references to read more about the Adapter pattern. Cons: It doesn't helps to understand the Adapter pattern in depth. The examples provided are not easy to comprehend ( unless you are an experienced programmer and not a beginner! ). Its not a good page to refer for the beginners.