Skip to content

Commit fa109db

Browse files
committed
Finish ch6 notes
1 parent d534569 commit fa109db

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

learning-python-design-patterns/notes.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,4 +256,37 @@ Python:
256256
### Disadvantages
257257
- Proxy pattern can increase the response time
258258

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

Comments
 (0)