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: chapters/design_patterns/adapter.md
+2-13
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,4 @@
1
1
---
2
-
layout: default
3
-
title: Adapter pattern
4
-
---
5
-
6
-
## Sample recipe template
7
-
8
-
Create a new `my-recipe.md` file and use this text as a start.
9
-
10
-
{% highlight text %}
11
-
---
12
2
layout: recipe
13
3
title: Adapter patter
14
4
chapter: Design patterns
@@ -17,9 +7,10 @@ chapter: Design patterns
17
7
18
8
Suppose we have 3-rd party grid component. We want to apply there our own custom sorting but a small problem. Our custom sorter does not implement required interface by grid component.
19
9
To understand the problem completely best example would be an socket from our usual life. Everybody knows this device. In some countries it has 3 pins and in other contries it has only 2 pins.
20
-
This is exactly right situation to use adapter.
10
+
This is exactly right situation to use [adapter pattern](https://en.wikipedia.org/wiki/Adapter_pattern).
21
11
22
12
## Solution
13
+
23
14
{% highlight coffeescript %}
24
15
# a fragment of 3-rd party grid component
25
16
class AwesomeGrid
@@ -58,5 +49,3 @@ agrid.sort() # sort data with custom sorter through adapter
58
49
59
50
Adapter is usefull when you have to organize an interaction between two objects with different interfaces. It can happen when you use 3-rd party libraries or you work with legacy code.
60
51
In any case be carefull with adapter: it can be helpfull but it can instigate design errors.
0 commit comments