Skip to content

Commit 41d487d

Browse files
authored
Few additions in readme
Adding Consequences and General usage of Adapter Pattern section to the Readme doc.
1 parent fb26d42 commit 41d487d

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

adapter/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,29 @@ incompatible interfaces.
2121

2222
![alt text](./etc/adapter.png "Adapter")
2323

24+
## General usage of Adapter Pattern:
25+
+ Wrappers used to adopt 3rd parties libraries and frameworks - most of the applications using third party libraries use adapters as a middle layer between the application and the 3rd party library to decouple the application from the library. If another library has to be used only an adapter for the new library is required without having to change the application code.
26+
2427
## Applicability
2528
Use the Adapter pattern when
2629

2730
* you want to use an existing class, and its interface does not match the one you need
2831
* you want to create a reusable class that cooperates with unrelated or unforeseen classes, that is, classes that don't necessarily have compatible interfaces
2932
* you need to use several existing subclasses, but it's impractical to adapt their interface by subclassing every one. An object adapter can adapt the interface of its parent class.
3033

34+
## Consequences:
35+
Class and object adapters have different trade-offs. A class adapter
36+
37+
* adapts Adaptee to Target by committing to a concrete Adaptee class. As a consequence, a class adapter won’t work when we want to adapt a class and all its subclasses.
38+
* let’s Adapter override some of Adaptee’s behavior, since Adapter is a subclass of Adaptee.
39+
* introduces only one object, and no additional pointer indirection is needed to get to the adaptee.
40+
41+
An object adapter
42+
43+
* let’s a single Adapter work with many Adaptees—that is, the Adaptee itself and all of its subclasses (if any). The Adapter can also add functionality to all Adaptees at once.
44+
* makes it harder to override Adaptee behavior. It will require subclassing Adaptee and making Adapter refer to the subclass rather than the Adaptee itself.
45+
46+
3147
## Real world examples
3248

3349
* [java.util.Arrays#asList()](http://docs.oracle.com/javase/8/docs/api/java/util/Arrays.html#asList%28T...%29)

0 commit comments

Comments
 (0)