community
directory
books
authors
images
encyclopedia

Email:
Password:
Register

Knowledgerush Search

 

Google
  Web knowledgerush


Search for images of Adapter pattern


Message boards   Post comment

Adapter pattern

In computer programming, the adapter design pattern '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.

There are two types of adapter patterns:

  • The 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 a physical instance of the wrapped object.
  • The 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. The Object Adapter pattern is more often used as some popular languages such as Java do not support multiple inheritance and it is generally thought of as bad practice.

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.

External Links

Sample

/* * Java code sample */

interface Stack { public void push (Object); public Object pop (); public Object top (); }

/* DoubleLinkedList */ class DList { public void insert (DNode pos, Object o) { ... } public void remove (DNode pos, Object o) { ... } public void insertHead (Object o) { ... } public void insertTail (Object o) { ... } public Object removeHead () { ... } public Object removeTail () { ... } public Object getHead () { ... } public Object getTail () { ... } }

/* Adapt DList class to Stack interface */ class DListImpStack extends DList implements Stack { public void push (Object o) { insertTail (o); } public Object pop () { return removeTail (); }

public Object top () { return getTail (); } }

Referenced By

Builder pattern | Design Patterns | Design pattern (computer science) | Design pattern (computing) | Prototype pattern | Software design pattern | Software desisgn pattern | Software pattern

 

Compose Your Message

Your Email Address or Pen Name (optional):
Subject:
Your Message:
 

 

 

 

 

 

This article is licensed under the GNU Free Documentation License. It uses material from the Wikipedia article "Adapter pattern".

 

Contact UsPrivacy Statement & Terms of Use

 
Copyright © 1999-2003 Knowledgerush.com. All rights reserved.