Skip to content

Commit c8b79ee

Browse files
committed
Finish ch7 notes
1 parent fa109db commit c8b79ee

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
@@ -289,4 +289,37 @@ Python:
289289
- Simplifies testing, maintenance, and troubleshooting problems
290290
- System can be easily broken down into definable elements
291291

292-
# Ch7. The command pattern - encapsulating invocation
292+
# Ch7. The command pattern - encapsulating invocation
293+
> Behavioral design pattern in which an object is used to encapsulate all the information needed to perform an action or trigger an event at a later time
294+
295+
## Understanding the command design pattern
296+
- A `Command` object knows about the `Receiver` objects and invokes a method of the `Receiver` object
297+
- Values for parameters of the receiver method are stored in the `Command` object
298+
- The invoker knows how to execute a command
299+
- The client creates a `Command` object and sets its receiver
300+
301+
### Intentions
302+
- Encapsulating a request as an object
303+
- Allowing the parametrization of clients with different requests
304+
- Allowing to save the requests in a queue
305+
- Providing an object-oriented callback
306+
307+
### Scenarios of use
308+
- Parametrizing objects depending on the action to be performed
309+
- Adding actions to a queue and executing requests at different points
310+
- Creating a structure for high-level operations that are based on smaller operations
311+
- E.g.:
312+
- Redo or rollback operations
313+
- Asynchronous task execution
314+
315+
## Advantages
316+
- Decouples the classes that invoke the operation from the object that knows how to execute the operation
317+
- Provide a queue system
318+
- Extensions to add new commands are easy
319+
- A rollback system with the command pattern can be defined
320+
321+
## Disadvantages
322+
- High number of classes and objects working together to achieve a goal
323+
- Every individual command is a `ConcreteCommand` class that increases the volume of classes for implementation and maintenance
324+
325+
# Ch8. The templated method pattern - encapsulating algorithm

0 commit comments

Comments
 (0)