FACTOID # 64: Sri Lanka has lowest divorce rate in the world - and the highest rate of female suicide.
 
 Home   Encyclopedia   Statistics   Countries A-Z   Flags   Maps   Education   Forum   FAQ   About 
 
 
 
WHAT'S NEW
RECENT ARTICLES
More Recent Articles »
 

SEARCH ALL

FACTS & STATISTICS    Advanced view

Search encyclopedia, statistics and forums:

 

 

(* = Graphable)

 

 


Encyclopedia > Adapter pattern

In computer programming, the adapter design pattern (often referred to as the wrapper pattern or simply a wrapper) 'adapts' one interface for a class into one that a client expects. An adapter allows classes to work together that normally could not because of incompatible interfaces by wrapping its own interface around that of an already existing class. The adapter is also responsible for handling any logic necessary to transform data into a form that is useful for the consumer. For instance, if multiple boolean values are stored as a single integer but your consumer requires a 'true'/'false', the adapter would be responsible for extracting the appropriate values from the integer value. Programming redirects here. ... In software engineering, a design pattern is a general repeatable solution to a commonly occurring problem in software design. ... An interface defines the communication boundary between two entities, such as a piece of software, a hardware device, or a user. ... In object-oriented programming, a class is a programming language construct used to group related fields and methods. ...


There are two types of adapter patterns:

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.
The object adapter pattern expressed in UML. The adapter hides the adaptee's interface from the client.
The object adapter pattern expressed in UML. The adapter hides the adaptee's interface from the client.
Class Adapter pattern 
This type of adapter uses multiple inheritance to achieve its goal. The adapter is created inheriting interfaces from both the interface that is expected and the interface that is pre-existing. Note that when the adapter must adapt multiple adaptees, the Class Adapter pattern cannot be used in languages such as Java that do not support multiple inheritance.
The class adapter pattern expressed in UML.
The class adapter pattern expressed in UML.

The adapter pattern is useful in situations where an already existing class provides some or all of the services you need but does not use the interface you need. A good real life example is an adapter that converts the interface of a Document Object Model of an XML document into a tree structure that can be displayed. A link to a tutorial that uses the adapter design pattern is listed in the links below. An object is fundamental concept in object-oriented programming. ... Image File history File links ObjectAdapter. ... Image File history File links ObjectAdapter. ... In the field of software engineering, the Unified Modeling Language (UML) is a standardized specification language for object modeling. ... Multiple inheritance refers to a feature of object-oriented programming languages in which a class can inherit behaviors and features from more than one superclass. ... Java language redirects here. ... Image File history File links ClassAdapter. ... Image File history File links ClassAdapter. ... In the context of Enterprise architecture, Service-orientation and Service-oriented architecture, the term service refers to a discretely defined set of contiguous and autonomous business or technical functionality. ... An interface defines the communication boundary between two entities, such as a piece of software, a hardware device, or a user. ... Hierarchy of objects in an example HTML DOM - Document Object Model The Document Object Model (DOM) is a platform- and language-independent standard object model for representing HTML or XML and related formats. ... The Extensible Markup Language (XML) is a general-purpose markup language. ...


Sample - Object Adapter

 # Python code sample class Target(object): def specific_request(self): return 'Hello Adapter Pattern!' class Adapter(object): def __init__(self, adaptee): self.adaptee = adaptee def request(self): return self.adaptee.specific_request() client = Adapter(Target()) print client.request() 

Sample - Class Adapter

 /** * Java code sample */ /* the client class should instantiate adapter objects */ /* by using a reference of this type */ interface Stack<T> { void push (T o); T pop (); T top (); } /* DoubleLinkedList is the adaptee class */ class DList<T> { public void insert (DNode pos, T o) { ... } public void remove (DNode pos) { ... } public void insertHead (T o) { ... } public void insertTail (T o) { ... } public T removeHead () { ... } public T removeTail () { ... } public T getHead () { ... } public T getTail () { ... } } /* Adapt DList class to Stack interface is the adapter class */ class DListImpStack<T> extends DList<T> implements Stack<T> { public void push (T o) { insertTail (o); } public T pop () { return removeTail (); } public T top () { return getTail (); } } 

External links

  • Description in Portland Pattern Repository's Wiki
  • Java Tutorial on the Document Object Model (uses the adapter pattern)
  • Citations from CiteSeer
  • Jt J2EE Pattern Oriented Framework
In software engineering, a design pattern is a general repeatable solution to a commonly occurring problem in software design. ... This article is about the book by Gamma et al. ... A software design pattern, the Abstract Factory Pattern provides a way to encapsulate a group of individual factories that have a common theme. ... The Builder Pattern is a software design pattern. ... The factory method pattern is an object-oriented design pattern. ... A prototype pattern is a creational design pattern used in software development when the type of objects to create is determined by a prototypical instance, which is cloned to produce new objects. ... In software engineering, the singleton pattern is a design pattern that is used to restrict instantiation of a class to one object. ... The bridge pattern is a design pattern used in software engineering which is meant to decouple an abstraction from its implementation so that the two can vary independently (Gamma et. ... This does not cite any references or sources. ... For decorators in Python, see Python syntax and semantics#Decorators. ... The façade pattern is an object-oriented design pattern. ... Flyweight is a software design pattern. ... // In computer programming, the proxy pattern is a software design pattern. ... In Object Oriented Design, the chain-of-responsibility pattern is a design pattern consisting of a source of command objects and a series of processing objects. ... In object-oriented programming, the Command pattern is a design pattern in which objects are used to represent actions. ... In computer programming, the interpreter pattern is a particular design pattern. ... In object-oriented programming, an iterator is an object allowing one to sequence through all of the elements or parts contained in some other object, typically a container or list. ... The mediator pattern is a software design pattern that provides a unified interface to a set of interfaces in a subsystem. ... The memento pattern is a software design pattern that provides the ability to restore an object to its previous state (undo by rollback). ... The observer pattern (sometimes known as publish/subscribe) is a design pattern used in computer programming to observe the state of an object in a program. ... A behavioral software design pattern, state pattern is used in computer programming to represent the state of an object. ... In computer programming, the strategy pattern is a particular software design pattern, whereby algorithms can be selected on-the-fly at runtime. ... Template method: UML class diagram. ... In object-oriented programming and software engineering, the visitor design pattern is a way of separating an algorithm from an object structure. ...


 
 

COMMENTARY     


Share your thoughts, questions and commentary here
Your name
Your comments

Want to know more?
Search encyclopedia, statistics and forums:

 


Lesson Plans | Student Area | Student FAQ | Reviews | Press Releases |  Feeds | Contact
The Wikipedia article included on this page is licensed under the GFDL.
Images may be subject to relevant owners' copyright.
All other elements are (c) copyright NationMaster.com 2003-5. All Rights Reserved.
Usage implies agreement with terms, 1022, m