Skip to content

Commit b706ff8

Browse files
committed
complete adapter pattern
1 parent e963992 commit b706ff8

File tree

2 files changed

+34
-17
lines changed

2 files changed

+34
-17
lines changed

CreationalPatterns/Singleton/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ This double-checked locking approach solves the thread concurrency problems whil
118118

119119
## Relations with Other Patterns
120120

121-
* **AbstractFactory*, **Builder**, **Prototype** - These patterns can be implemented using the Singleton pattern
121+
* **AbstractFactory**, **Builder**, **Prototype** - These patterns can be implemented using the Singleton pattern
122122
* **Flyweight** - There should be only one Singleton instance, whereas Flyweight class can have multiple instances with a different intrinsic state. Whatsmore, Singleton object can be mutable but Flyweight objects are immutable.
123123

124124
Reference:

StructuralPatterns/Adapter/README.md

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,42 @@
1111

1212
Write a `Adapter` class that adapts the new vendor interface into the one you're expecting. The adapter acts as the middleman by receiving requests from the client and converting them into requests that make sense on the vendor class.
1313

14-
## Benefits
14+
## Common Structure
15+
16+
There are two variations, namely **Object Adapter** and **Class Adapter**.
17+
18+
![Common structure of adapter pattern](https://upload.wikimedia.org/wikipedia/commons/e/e5/W3sDesign_Adapter_Design_Pattern_UML.jpg)
19+
20+
* Target (Duck)
21+
* defines the domain-specific interface that client uses.
22+
* Adapter (TurkeyClassAdapter, TurkeyObjectAdapter)
23+
* adapts the interface Adaptee to the Target interface.
24+
* Adaptee (Turkey)
25+
* defines an existing interface that needs adapting.
26+
* Client
27+
* collaborates with objects conforming to the Target interface.
28+
29+
_[Source: http://www.dofactory.com/net/adapter-design-pattern]_
30+
31+
## Collaboration
32+
33+
Clients call operations on an Adapter instance. In turn, the adapter callas Adaptee operations that carry out the request.
34+
35+
## Consequences
36+
37+
### Pattern in General
38+
39+
**Benefits**
1540

1641
* It allows more flexibility in design
1742
* They handle logic by wrapping a new interface around that of an exisiting class so you can use new APIs and avoid breaking existing implementations.
1843
* It absolutely interconnects two incompatible interfaces.
1944

20-
## Drawbacks
45+
**Drawbacks**
2146

2247
* Sometimes many adaptations are required along an adapter chain to reach the required type.
2348

24-
## Class Adapter (eg. `Stack<E> extends Vector<E>`)
49+
### Class Adapter (eg. `Stack<E> extends Vector<E>`)
2550

2651
**Benefits**
2752

@@ -33,7 +58,7 @@ Write a `Adapter` class that adapts the new vendor interface into the one you're
3358
* The whole interface of the existing class is visible
3459
* Not able to adapt all the subclasses of the existing class at one go. You have to define explicitely which (sub-)class you adapt.
3560

36-
## Object Adapter
61+
### Object Adapter
3762

3863
**Benefits**
3964

@@ -147,18 +172,10 @@ static void testDuck(IDuck duck)
147172
duck.Fly();
148173
}
149174
```
175+
## Relations with Other Patterns
150176

151-
## Common Structure
152-
153-
![Common structure of adapter pattern](https://upload.wikimedia.org/wikipedia/commons/e/e5/W3sDesign_Adapter_Design_Pattern_UML.jpg)
177+
* **Bridge** has a structure similar to an object adapter, but Bridge has a different intent. It is meant to separate an interface from its implementation so that they can be variaed easily and independently. An adapter is meant to change the interface of an *existing* object.
154178

155-
* Target (Duck)
156-
* defines the domain-specific interface that client uses.
157-
* Adapter (TurkeyClassAdapter, TurkeyObjectAdapter)
158-
* adapts the interface Adaptee to the Target interface.
159-
* Adaptee (Turkey)
160-
* defines an existing interface that needs adapting.
161-
* Client
162-
* collaborates with objects conforming to the Target interface.
179+
* **Decorator** enhances another object without changing its interface. A decorator is thus more transparent to the application than an adapter is. As a consequence, Decorator supports recursive composition, which isn't possible with pure adapters.
163180

164-
_[Source: http://www.dofactory.com/net/adapter-design-pattern]_
181+
* **Proxy** defines a representative or surrogate for another object and does not change its interface.

0 commit comments

Comments
 (0)