| Adapter Pattern |
Article Index for Adapter |
Website Links For Adapter |
Information AboutAdapter Pattern |
| CATEGORIES ABOUT ADAPTER PATTERN | |
| software design patterns | |
| articles with example java code | |
|
There are two types of adapter patterns:
The adapter pattern is useful in situations where an already existing class provides some or all of the Service s 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 ADAPTOR1
interface Stack { void push (Object); Object pop (); Object top (); }
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 () { ... } }
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
interface Stack { void push (Object o); Object pop (); Object top (); }
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 () { ... } }
class DListStack implements 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
|
|
|