Very simple design pattern that lets components process a command or query in turn
Simplest: simply make a reference chain, in theory, you could replace it with just an ordinary List, or perhaps, a LinkedList
Method Chain = singly-linked List essentially
More Sophisticated: Broker Chain. Implementation that also leverages Mediator and Observer patterns allows us to process queries on an event, letting each subscriber perform modifications of the originally passed object (single reference that goes through entire chain) before final values are returned to the client
Problem: no record of change / history on variable assignment
Solution: instead of working with objects directly by manipulating them through their APIs, we send them commands or instructions on how to do something.
Components can communicate with one another using special objects that encapsulate instructions, rather than specifying those same instructions as arguments to a method
Command Steps:
Command Undo Operations:
Composite Command:
Uncommon pattern and removed from many universities
Has been deliberately hidden in C# in favor of the simple IEnumerator/IEnumerable dupoply
ReactiveX also prides itself with implementing the iterator pattern
situations when you don't necessarily want objects to be aware of each other's presence. (or maybe do but DON't want them to communicate through references...)
having an in-between componenet that everyone in the system has a reference to and can use to communicate with one another
Chat room
Simplest: member list and a function that goes through the list and does what is intended to do
Sophisticated: use events to allow participants to subscribe (and unsub) to things happening in the system...this way messages from one component to another can be treated as events.
when you care about being able to roll back the system to a particular state, if need be ...stores the state of the system and returns it as a dedicated, read-only object with no behavior of its own. "Token" used for feeding back into the system to restore its state
all about handing out tokens that can be used to restore the system to a prior state.
You don't want a piece of functionality but it's built into the interface....you make a NULL object
let's one component notify other components that something has happened
Thread safety is one concern when it comes to Observer, whether talking individual events or entire collections
Observer Examples
State Machines involve two collections: states and triggers. States model the possible states of the system and triggers transition us from one state to another.
TWO ways to model states:
More State Notes:
allows you to define a skeleton of an algorithm and then use composition to supply the missing implementation details related to a particular strategy.
Dynamic strategy simply keeps a reference to the strategy currently (if you want to change to different strat...just change the reference)
very similar to strategy method
Strategy uses composition (whether dynamic or static) while Template uses inheritance
allows us to add some distinct behavior to every element in a heiarchy of objects
Intrusive Visitor - adding a method to every single object in the hierarchy. (breaks OCP)
Reflective - adding a separate Visitor that requires no changes to the objects. (uses the is/as whenever runtime dispatch as needed)
Dynamic - forces runtime dispatch via the DLR by casting hierarchy objects to dynamic.
Classic - (double dispatch) every element of the hierarchy learns to Accept() a Visitor. We then subclass the Visitor to enhance the hiearchy's funtionality in all sorts of directions
Acyclic Visitor
Cyclic Visitor (baed on funciton overloading
Acyclic Visitor based on type casting)