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
**Strategy**: defines a family of algorithms, encapsulates each one and makes them interchangeable. Strategy lets the algorithm vary independently from clients that use it.
3
+
> **Strategy**: defines a family of algorithms, encapsulates each one and makes them interchangeable. Strategy lets the algorithm vary independently from clients that use it.
4
4
5
5
I think the more pythonic approach would be to define methods rather than classes, and this would not violate the above definition. The class-based approach is needed in Java and has the advantage of explicitly setting out the required method in an abstract base class.
Copy file name to clipboardExpand all lines: chapter03_decorator/readme.md
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Chapter 3: Decorator design pattern
2
2
3
-
**Decorator**: Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.
3
+
> **Decorator**: Attach additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality.
4
4
5
5
Not quite the same as python [decorator syntax](https://docs.python.org/3/reference/compound_stmts.html#grammar-token-decorators) as in python you call the _decorated function_ and the decorating function is called first whereas the _decorating function_ must be called here.
**Simple Factory**: A class which chooses which product class to instantiate and return, based upon method parameters.
3
+
> **Simple Factory**: A class which chooses which product class to instantiate and return, based upon method parameters.
4
4
5
5
The Python standard library contains multiple references to factory objects, for instances in [dataclasses](https://docs.python.org/3/library/dataclasses.html?highlight=factory)
6
6
7
-
**Factory Method**: Defines an interface for creating an object, but lets subclasses decide which class to instantiate. The Factory method lets a class defer instantiation to subclasses.
7
+
> **Factory Method**: Defines an interface for creating an object, but lets subclasses decide which class to instantiate. The Factory method lets a class defer instantiation to subclasses.
8
8
9
9
For instance the `PizzaStore` abstract class in this repo provides an abstract `create_pizza` interface for creating one product.
10
10
11
-
**Abstract Factory**: Provides an interface for creating families of related or dependent objects without specifying their concrete classes.
11
+
> **Abstract Factory**: Provides an interface for creating families of related or dependent objects without specifying their concrete classes.
12
12
13
13
For instance the `PizzaIngredientFactory` abstract class defines an interface for a family of products.
0 commit comments