Google
 
   
Login
Username:

Password:


Lost Password?

Register now!
Search
Main Menu
top books
Polls
What do you think about php-deluxe.net?
Excellent!
Cool
Hmm..not bad
What the hell is this?
encyclopedia
recommendation
compare webbrowser
Freenet DSL
Who's Online
10 user(s) are online (10 user(s) are browsing encyclopedia)

Members: 0
Guests: 10

more...
browser tip
Unix Befehle
manual of unix befehle
recommendation!
Sponsored
partner

Adapter pattern

In computer programming, the adapter design pattern (computer science) adapts one Interface (computer science) for a Class (computer science) 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 (computing).
  • The Class Adapter pattern - This type of adapter uses multiple inheritance (object-oriented programming) 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 programming language, such as Java programming language, do not support true multiple inheritance as 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.

    = Sample - Class Adaptor =

    /** * Java code sample */ interface Stack (computing) { 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 (); } }

    = Sample - Object Adapter =

    /** * Java code sample */ class Stack (computing) { public Stack() { ... } public void push (Object o) { ... } 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 DListStack extends Stack { private DList _dlist; public DListStack() { _dlist = new DList()} public void push (Object o) { _dlist.insertTail (o); } public Object pop () { return _dlist.removeTail (); } public Object top () { return _dlist.getTail (); } }

    =External links=

    *[http://www.c2.com/cgi/wikiAdapterPattern Description in Portland Pattern Repository s Wiki] *[http://java.sun.com/webservices/jaxp/dist/1.1/docs/tutorial/dom/ Java Tutorial on the Document Object Model] (uses the adapter pattern) *[http://citeseer.org/csq=Adapter+pattern Citations from CiteSeer]