You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: adapter/README.md
+15-15Lines changed: 15 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -18,10 +18,10 @@ couldn't otherwise because of incompatible interfaces.
18
18
19
19
##Explanation
20
20
21
-
Realworld example
21
+
Real-world example
22
22
23
-
>Consider that you have some picturesin your memory card and you need to transfer them to your computer.In order totransfer them you need some kind of adapter that is compatible with your computer ports so that you can attach memory card to your computer. In this case card reader is an adapter.
24
-
>Another example would be the famous power adapter; a threelegged plug can't be connected to a twopronged outlet, it needs to use a power adapter that makes it compatible with the twoprongedoutlet.
23
+
>Consider that you have some pictureson your memory card and you need to transfer them to your computer.Totransfer them, you need some kind of adapter that is compatible with your computer ports so that you can attach a memory card to your computer. In this case card reader is an adapter.
24
+
>Another example would be the famous power adapter; a three-legged plug can't be connected to a two-pronged outlet, it needs to use a power adapter that makes it compatible with the two-prongedoutlets.
25
25
>Yet another example would be a translator translating words spoken by one person to another
26
26
27
27
In plain words
@@ -36,7 +36,7 @@ Wikipedia says
36
36
37
37
Consider a captain that can only use rowing boats and cannot sail at all.
38
38
39
-
First we have interfaces`RowingBoat` and`FishingBoat`
39
+
First, we have interfaces`RowingBoat` and`FishingBoat`
40
40
41
41
```java
42
42
publicinterfaceRowingBoat {
@@ -68,7 +68,7 @@ public class Captain {
68
68
}
69
69
```
70
70
71
-
Now let's say the pirates are coming and our captain needs to escape but there is only fishing boat available. We need to create an adapter that allows the captain to operate the fishing boat with his rowing boat skills.
71
+
Now let's say the pirates are coming and our captain needs to escape but there is onlyafishing boat available. We need to create an adapter that allows the captain to operate the fishing boat with his rowing boat skills.
72
72
73
73
```java
74
74
@Slf4j
@@ -100,25 +100,25 @@ captain.row();
100
100
##Applicability
101
101
Use the Adapter pattern when
102
102
103
-
*you want to use an existing class, and its interface does not match the one you need
104
-
*you want to create a reusable class that cooperates with unrelated or unforeseen classes, that is, classes that don't necessarily have compatible interfaces
105
-
*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.
106
-
*most of the applications using thirdparty 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.
103
+
*You want to use an existing class, and its interface does not match the one you need
104
+
*You want to create a reusable class that cooperates with unrelated or unforeseen classes, that is, classes that don't necessarily have compatible interfaces
105
+
*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.
106
+
*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.
107
107
108
108
##Consequences:
109
109
Class and object adapters have different trade-offs. A class adapter
110
110
111
-
*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.
112
-
*let’s Adapter override some of Adaptee’s behavior, since Adapter is a subclass of Adaptee.
113
-
*introduces only one object, and no additional pointer indirection is needed to get to the adaptee.
111
+
*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.
112
+
*Let’s Adapter override some of Adaptee’s behavior since Adapter is a subclass of Adaptee.
113
+
*Introduces only one object, and no additional pointer indirection is needed to get to the adaptee.
114
114
115
115
An object adapter
116
116
117
-
*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.
118
-
*makes it harder to override Adaptee behavior. It will require subclassing Adaptee and making Adapter refer to the subclass rather than the Adaptee itself.
117
+
*Lets 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.
118
+
*Makes it harder to override Adaptee behavior. It will require subclassing Adaptee and making the Adapter refer to the subclass rather than the Adaptee itself.