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
Adapter Use Case | <aid="udemyVideoLink"href="https://www.udemy.com/course/design-patterns-in-python/learn/lecture/25400220/?referralCode=7493DBBBF97FF2B0D24D"target="_blank"title="Adapter Use Case"><imgsrc="/img/udemy_btn_sm.gif"alt="Adapter Use Case"/></a> <aid="ytVideoLink"href="https://youtu.be/fyws-p4WHuk"target="_blank"title="Adapter Use Case"><imgsrc="/img/yt_btn_sm.gif"alt="Adapter Use Case"/></a> <aid="skillShareVideoLink"href="https://skl.sh/34SM2Xg"target="_blank"title="Adapter Use Case"><imgsrc="/img/skillshare_btn_sm.gif"alt="Adapter Use Case"/></a> <aid="sbcodeVideoLink"href="#"><inputtype="image"src="/img/sbcode_btn_sm.gif"onclick="selectVideoId()"></a>
Python **time** Module | <aid="udemyVideoLink"href="https://www.udemy.com/course/design-patterns-in-python/learn/lecture/25414958/?referralCode=7493DBBBF97FF2B0D24D"target="_blank"title="Python time Module"><imgsrc="/img/udemy_btn_sm.gif"alt="Python time Module"/></a> <aid="ytVideoLink"href="https://youtu.be/WZTZeGB3o3U"target="_blank"title="Python time Module"><imgsrc="/img/yt_btn_sm.gif"alt="Python time Module"/></a> <aid="skillShareVideoLink"href="https://skl.sh/34SM2Xg"target="_blank"title="Python time Module"><imgsrc="/img/skillshare_btn_sm.gif"alt="Python time Module"/></a> <aid="sbcodeVideoLink"href="#"><inputtype="image"src="/img/sbcode_btn_sm.gif"onclick="selectVideoId()"></a>
11
+
3
12
## Book
4
13
5
14
Cover | Links
@@ -161,11 +170,3 @@ I also use the `time` module to sleep for a second between loops to simulate a 1
161
170
```
162
171
163
172
When executing [/adapter/cube_a.py](/adapter/cube_a.py) you will notice that the process will run for about 10 seconds outputting the gradual progress of the construction of each cube.
164
-
165
-
## Summary
166
-
167
-
* Use the Adapter when you want to use an existing class, but its interface does not match what you need.
168
-
* The adapter adapts to the interface of its parent class for those situations when it is not viable to modify the parent class to be domain-specific for your use case.
169
-
* Adapters will most likely provide an alternative interface over an existing object, class or interface, but it can also provide extra functionality that the object being adapted may not already provide.
170
-
* An adapter is similar to a [Decorator](/decorator) except that it changes the interface to the object, whereas the decorator adds responsibility without changing the interface. This also allows the Decorator to be used recursively.
171
-
* An adapter is similar to the [Bridge](/bridge) pattern and may look identical after the refactoring has been completed. However, the intent of creating the Adapter is different. The Bridge is a result of refactoring existing interfaces, whereas the Adapter is about adapting over existing interfaces that are not viable to modify due to many existing constraints. E.g., you don't have access to the original code or it may have dependencies that already use it and modifying it would affect those dependencies negatively.
| Bridge Use Case | <aid="udemyVideoLink"href="https://www.udemy.com/course/design-patterns-in-python/learn/lecture/25451262/?referralCode=7493DBBBF97FF2B0D24D"target="_blank"title="Bridge Use Case"><imgsrc="/img/udemy_btn_sm.gif"alt="Bridge Use Case"/></a> <aid="ytVideoLink"href="https://youtu.be/E7T09yfROQ4"target="_blank"title="Bridge Use Case"><imgsrc="/img/yt_btn_sm.gif"alt="Bridge Use Case"/></a> <aid="skillShareVideoLink"href="https://skl.sh/34SM2Xg"target="_blank"title="Bridge Use Case"><imgsrc="/img/skillshare_btn_sm.gif"alt="Bridge Use Case"/></a> <aid="sbcodeVideoLink"href="#"><inputtype="image"src="/img/sbcode_btn_sm.gif"onclick="selectVideoId()"></a>|
In this example, I draw a square and a circle. Both of these can be categorized as shapes.
78
87
79
-
The shape is set up as the abstraction interface. The refined abstractions, `Square` and `Circle`, implement the `IShape` interface.
88
+
The shape is set up as the abstraction interface. The refined abstractions, `Square` and `Circle`, implement the `IShape` interface.
80
89
81
90
When the Square and Circle objects are created, they are also assigned their appropriate implementers being `SquareImplementer` and `CircleImplementer` .
82
91
@@ -95,18 +104,22 @@ python ./bridge/client.py
95
104
******
96
105
****
97
106
**
107
+
98
108
**
99
109
**
110
+
100
111
**
101
112
****
102
113
******
103
114
**************
115
+
104
116
**
105
117
**
106
118
**
107
119
**
108
120
**
109
121
**
122
+
110
123
**************
111
124
```
112
125
@@ -143,7 +156,7 @@ Outputs
143
156
144
157
A Python **Tuple** is similar to a [List](/builder#python-list). Except that the items in the Tuple are ordered, unchangeable and allow duplicates.
145
158
146
-
A Tuple can be instantiated using the round brackets `()` or `tuple()`, verses `[]` for a [List](/builder#python-list) and `{}` for a [Set](/observer#python-set) or [Dictionary](/singleton#python-dictionary).
159
+
A Tuple can be instantiated using the round brackets `()` or `tuple()`, verses `[]` for a [List](/builder#python-list) and `{}` for a [Set](/observer#python-set) or [Dictionary](/singleton#python-dictionary).
147
160
148
161
```python
149
162
PS> python
@@ -153,10 +166,3 @@ PS> python
153
166
>>>print(len(items))
154
167
4
155
168
```
156
-
157
-
## Summary
158
-
159
-
* Use when you want to separate a solution where the abstraction and implementation may be tightly coupled and you want to break it up into smaller conceptual parts.
160
-
* Once you have added the bridge abstraction, you should be able to extend each side of it separately without breaking the other.
161
-
* Also, once the bridge abstraction exists, you can more easily create extra concrete implementations for other similar products that may also happen to be split across similar conceptual lines.
162
-
* The Bridge pattern is similar to the adapter pattern except in the intent that you developed it. The bridge is an approach to refactor already existing code, whereas the adapter adapts to the existing code through its existing interfaces and methods without changing the internals.
Composite Use Case | <aid="udemyVideoLink"href="https://www.udemy.com/course/design-patterns-in-python/learn/lecture/25473576/?referralCode=7493DBBBF97FF2B0D24D"target="_blank"title="Composite Use Case"><imgsrc="/img/udemy_btn_sm.gif"alt="Composite Use Case"/></a> <aid="ytVideoLink"href="https://youtu.be/5MjYcxO_TUk"target="_blank"title="Composite Use Case"><imgsrc="/img/yt_btn_sm.gif"alt="Composite Use Case"/></a> <aid="skillShareVideoLink"href="https://skl.sh/34SM2Xg"target="_blank"title="Composite Use Case"><imgsrc="/img/skillshare_btn_sm.gif"alt="Composite Use Case"/></a> <aid="sbcodeVideoLink"href="#"><inputtype="image"src="/img/sbcode_btn_sm.gif"onclick="selectVideoId()"></a>
Visit [https://docs.python.org/3/reference/expressions.html#conditional-expressions](https://docs.python.org/3/reference/expressions.html#conditional-expressions) for more examples of conditional expressions.
142
-
143
-
## Summary
144
-
145
-
* The Composite design pattern allows you to structure components in a manageable hierarchal order.
146
-
* It provides flexibility of structure since you can add/remove and reorder components.
147
-
* File explorer on windows is a very good example of the composite design pattern in use.
148
-
* Any system where you need to offer at runtime the ability to group, un-group, modify multiple objects at the same time, would benefit from the composite design pattern structure. Programs that allow you to draw shapes and graphics will often also use this structure as well.
Example Use Case | <aid="ytVideoLink"href="https://youtu.be/8uDGo9DjHUc"target="_blank"title="Use Case"><imgsrc="/img/yt_btn_sm.gif"alt="Use Case"/></a>
Decorator Use Case | <aid="udemyVideoLink"href="https://www.udemy.com/course/design-patterns-in-python/learn/lecture/25378590/?referralCode=7493DBBBF97FF2B0D24D"target="_blank"title="Decorator Use Case"><imgsrc="/img/udemy_btn_sm.gif"alt="Decorator Use Case"/></a> <aid="ytVideoLink"href="https://youtu.be/8uDGo9DjHUc"target="_blank"title="Decorator Use Case"><imgsrc="/img/yt_btn_sm.gif"alt="Decorator Use Case"/></a> <aid="skillShareVideoLink"href="https://skl.sh/34SM2Xg"target="_blank"title="Decorator Use Case"><imgsrc="/img/skillshare_btn_sm.gif"alt="Decorator Use Case"/></a> <aid="sbcodeVideoLink"href="#"><inputtype="image"src="/img/sbcode_btn_sm.gif"onclick="selectVideoId()"></a>
@@ -148,12 +148,3 @@ In all the classes in the above use case example that implement the `IValue` int
148
148
```
149
149
150
150
The `__str__` dunder was also overridden in the [/prototype/prototype_concept.py](/prototype/prototype_concept.py) concept code.
151
-
152
-
## Summary
153
-
154
-
* Use the decorator when you want to add responsibilities to objects dynamically without affecting the inner object.
155
-
* You want the option to later remove the decorator from an object in case you no longer need it.
156
-
* It is an alternative method to creating multiple combinations of subclasses. I.e., Instead of creating a subclass with all combinations of objects A, B, C in any order, and including/excluding objects, you could create 3 objects that can decorate each other in any order you want. E.g., (D(A(C))) or (B(C)) or (A(B(A(C)))
157
-
* The decorator, compared to using static inheritance to extend, is more flexible since you can easily add/remove the decorators at runtime. E.g., use in a recursive function.
158
-
* A decorator supports recursive composition. E.g., halve(halve(number))
159
-
* A decorator shouldn't modify the internal objects data or references. This allows the original object to stay intact if the decorator is later removed.
0 commit comments