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: learning-python-design-patterns/notes.md
+34-1Lines changed: 34 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -256,4 +256,37 @@ Python:
256
256
### Disadvantages
257
257
- Proxy pattern can increase the response time
258
258
259
-
# Ch6. The observer pattern - keeping objects in the know
259
+
# Ch6. The observer pattern - keeping objects in the know
260
+
261
+
## Behavioral patterns
262
+
- Focus on the responsibilities that an object has
263
+
- Deal with the interaction among objects to achieve larger functionality
264
+
- Objects should be able to interact with each other, **but they should still be loosely coupled**
265
+
266
+
## Understanding the observer design pattern
267
+
> An object (Subject) maintains a list of dependents (Observers) so that the Subject can notify all the Observers about the changes that it undergoes using any of the methods defined by the Observer
268
+
269
+
- Defines a one-to-many dependency between objects so that any change in one object will be notified to the other dependent objects automatically
270
+
- Encapsulates the core component of the Subject
271
+
272
+
## The pull model
273
+
- Subject broadcasts to all the registered Observers when there is any change
274
+
- Observer is responsible for getting the changes or pulling data from the subscriber when there is an amendment
275
+
- Pull model is **ineffective**: involves two steps:
276
+
- Subject notifies the Observer
277
+
- Observer pulls the required data from the Subject
278
+
279
+
## The push model
280
+
- Changes are pushed by the Subject to the Observer
281
+
- Subject can send detailed information to the Observer (even though it may not be needed) -> can result in sluggish response times when a large amount of data in sent by the Subject but is never actually used by the Observer
282
+
283
+
## Loose coupling and the observer pattern
284
+
- Coupling refers to the degree of knowledge that one object has about the other object that it interacts with
285
+
286
+
> Loosely-coupled designs allow us to build flexbile object-oriented systems that can handle changes because they reduce the dependency between multiple objects
287
+
288
+
- Reduces the risk that a change made within one element might create an unanticipated impact on the other elements
289
+
- Simplifies testing, maintenance, and troubleshooting problems
290
+
- System can be easily broken down into definable elements
291
+
292
+
# Ch7. The command pattern - encapsulating invocation
0 commit comments