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
An example use case may be that you have a furniture shop front. You sell many different kinds of furniture. You sell chairs and tables. And they are manufactured at different factories using different unrelated processes that are not important for your concern. You only need the factory to deliver.
49
+
*...Refer to Book or Videos for extra content.*
50
50
51
-
You can create an extra module called `FurnitureFactory`, to handle the chair and table factories, thus removing the implementation details from the client.
51
+
<!-- An example use case may be that you have a furniture shop front. You sell many different kinds of furniture. You sell chairs and tables. And they are manufactured at different factories using different unrelated processes that are not important for your concern. You only need the factory to deliver.
52
+
53
+
You can create an extra module called `FurnitureFactory`, to handle the chair and table factories, thus removing the implementation details from the client. -->
Copy file name to clipboardExpand all lines: chain_of_responsibility/README.md
+7-2Lines changed: 7 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,7 +39,9 @@ The chain that the object will pass through is normally dynamic at runtime, alth
39
39
40
40
## Source Code
41
41
42
-
In this concept code, a chain is created with a default first successor. A number is passed to a successor, which then does a random test, and depending on the result will modify the number and then pass it onto the next successor. The process is randomized and will end at some point when there are no more successors designated.
42
+
*...Refer to Book or Videos for extra content.*
43
+
44
+
<!-- In this concept code, a chain is created with a default first successor. A number is passed to a successor, which then does a random test, and depending on the result will modify the number and then pass it onto the next successor. The process is randomized and will end at some point when there are no more successors designated. -->
43
45
44
46
## Output
45
47
@@ -57,11 +59,14 @@ Finished result = -1.5
57
59
58
60
## Example Use Case
59
61
62
+
*...Refer to Book or Videos for extra content.*
63
+
64
+
<!--
60
65
In the ATM example below, the chain is hard coded in the client first to dispense amounts of £50s, then £20s and then £10s in order.
61
66
62
67
This default chain order helps to ensure that the minimum number of notes will be dispensed. Otherwise, it might dispense 5 x £10 when it would have been better to dispense 1 x £50.
63
68
64
-
Each successor may be re-called recursively for each denomination depending on the value that was requested for withdrawal.
69
+
Each successor may be re-called recursively for each denomination depending on the value that was requested for withdrawal.-->
Copy file name to clipboardExpand all lines: command/README.md
+8-4Lines changed: 8 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -51,15 +51,17 @@ Uses:
51
51
52
52
## Source Code
53
53
54
-
The Client instantiates a Receiver that accepts certain commands.
54
+
*...Refer to Book or Videos for extra content.*
55
+
56
+
<!-- The Client instantiates a Receiver that accepts certain commands.
55
57
56
58
The Client then creates two Command objects that will call one of the specific commands on the Receiver.
57
59
58
60
The Client then creates an Invoker, E.g., a user interface with buttons, and registers both Commands into the Invokers dictionary of commands.
59
61
60
62
The Client doesn't call the receivers commands directly, but the via the Invoker, which then calls the registered Command objects `execute()` method.
61
63
62
-
This abstraction between the invoker, command and receiver, allows the Invoker to add extra functionality such as history, replay, UNDO/REDO, logging, alerting and any other useful things that may be required.
64
+
This abstraction between the invoker, command and receiver, allows the Invoker to add extra functionality such as history, replay, UNDO/REDO, logging, alerting and any other useful things that may be required.-->
63
65
64
66
## Output
65
67
@@ -73,13 +75,15 @@ Executing Command 2
73
75
74
76
## Example Use Case
75
77
76
-
This will be a smart light switch.
78
+
*...Refer to Book or Videos for extra content.*
79
+
80
+
<!-- This will be a smart light switch.
77
81
78
82
This light switch will keep a history of each time one of its commands was called.
79
83
80
84
And it can replay its commands.
81
85
82
-
A smart light switch could be extended in the future to be called remotely or automated depending on sensors.
86
+
A smart light switch could be extended in the future to be called remotely or automated depending on sensors.-->
Copy file name to clipboardExpand all lines: factory/README.md
+8-4Lines changed: 8 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -48,11 +48,13 @@ The Factory pattern is really about adding that extra abstraction between the ob
48
48
49
49
## Source Code
50
50
51
-
In this concept example, the client wants an object named `b`
51
+
*...Refer to Book or Videos for extra content.*
52
+
53
+
<!-- In this concept example, the client wants an object named `b`
52
54
53
55
Rather than creating `b` directly in the client, it asks the creator (factory) for the object instead.
54
56
55
-
The factory finds the relevant class using some kind of logic from the attributes of the request. It then asks the subclass to instantiate the new object which it then returns as a reference back to the client asking for it.
57
+
The factory finds the relevant class using some kind of logic from the attributes of the request. It then asks the subclass to instantiate the new object which it then returns as a reference back to the client asking for it.-->
56
58
57
59
## Output
58
60
@@ -63,11 +65,13 @@ ConcreteProductB
63
65
64
66
## Example Use Case
65
67
66
-
An example use case is a user interface where the user can select from a menu of items, such as chairs.
68
+
*...Refer to Book or Videos for extra content.*
69
+
70
+
<!-- An example use case is a user interface where the user can select from a menu of items, such as chairs.
67
71
68
72
The user has been given a choice using some kind of navigation interface, and it is unknown what choice, or how many the user will make until the application is actually running and the user starts using it.
69
73
70
-
So, when the user selected the chair, the factory then takes some property involved with that selection, such as an ID, Type or other attribute and then decides which relevant subclass to instantiate in order to return the appropriate object.
74
+
So, when the user selected the chair, the factory then takes some property involved with that selection, such as an ID, Type or other attribute and then decides which relevant subclass to instantiate in order to return the appropriate object.-->
This example mimics the **MVC** approach described earlier.
85
+
*...Refer to Book or Videos for extra content.*
86
+
87
+
<!-- This example mimics the **MVC** approach described earlier.
84
88
85
89
There is an external process called a `DataController`, and a client process that holds a `DataModel` and multiple `DataViews` which are a Pie graph, Bar graph and Table view.
86
90
@@ -94,7 +98,7 @@ The hypothetical external `DataController` then updates the external data, and t
94
98
95
99
Note that in reality this example would be much more complex if multiple servers are involved. I am keeping it brief to demonstrate one possible use case of the observer pattern.
96
100
97
-
Also note that in the `DataController`, the references to the observers are contained in a [Set](#python-set), while in the `DataModel` I have used a [Dictionary](/singleton#python-dictionary) instead, so that you can see an alternate approach.
101
+
Also note that in the `DataController`, the references to the observers are contained in a [Set](#python-set), while in the `DataModel` I have used a [Dictionary](/singleton#python-dictionary) instead, so that you can see an alternate approach.-->
Copy file name to clipboardExpand all lines: visitor/README.md
+8-4Lines changed: 8 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,13 +42,15 @@ Similar to the template pattern it could be used to output different versions of
42
42
43
43
## Source Code
44
44
45
-
In the concept code below, a hierarchy of any object is created. It is similar to a simplified composite. The objects of `Element` can also contain a hierarchy of sub elements.
45
+
*...Refer to Book or Videos for extra content.*
46
+
47
+
<!-- In the concept code below, a hierarchy of any object is created. It is similar to a simplified composite. The objects of `Element` can also contain a hierarchy of sub elements.
46
48
47
49
The `Element` class could also consist of many variations, but this example uses only one.
48
50
49
51
Rather than writing specific code inside all these elements every time I wanted to handle a new custom operation, I can implement the `IVisitable` interface and create the `accept()` method which allows the Visitor to pass through it and access the Elements internal attributes.
50
52
51
-
Two different Visitor classes are created, `PrintElementNamesVisitor` and `CalculateElementTotalsVisitor` . They are instantiated and passed through the existing Object hierarchy using the same `IVisitable` interface.
53
+
Two different Visitor classes are created, `PrintElementNamesVisitor` and `CalculateElementTotalsVisitor` . They are instantiated and passed through the existing Object hierarchy using the same `IVisitable` interface.-->
52
54
53
55
## Output
54
56
@@ -63,13 +65,15 @@ A
63
65
64
66
## Visitor Example Use Case
65
67
66
-
In the example, the client creates a car with parts.
68
+
*...Refer to Book or Videos for extra content.*
69
+
70
+
<!-- In the example, the client creates a car with parts.
67
71
68
72
The car and parts inherit an abstract car parts class with predefined property getters and setters.
69
73
70
74
Instead of creating methods in the car parts classes and abstract class that run bespoke methods, the car parts can all implement the `IVisitor` interface.
71
75
72
-
This allows for the later creation of Visitor objects to run specific tasks on the existing hierarchy of objects.
76
+
This allows for the later creation of Visitor objects to run specific tasks on the existing hierarchy of objects.-->
0 commit comments