What is it?
Design pattern that lets you define a family of methods
that are interchangeable at runtime
What problem does it solve?
Introduce new behaviours without violating the
Open-Closed principle
When should we use this pattern?
When we need multiple ways of achieving the same task
Currently, the code uses switch statements to handle each of the different cases.
How does the code violate the open/closed principle?
Currently, the code uses switch statements to handle each of the different cases.
How does the code violate the open/closed principle?
switch
statement.
Let's refactor it!
Find out more at Strategy (refactoring.guru)
What is it?
Define a subscription mechanism that notifies observers
about any event that happens to the subject that they
are observing
What problem does it solve?
Modelling a n-to-many relationship may be difficult. If
not done well, it typically leads to tight coupling
When should we use this pattern?
If there is a state that multiple observers are interested in
Model the system in Java!
What is it?
Behavioural design pattern that allows an object to alter its behaviour when its internal state changes.
When should we use this pattern?
Text
Player
has methods that can change its statePlayer
changes based on its state
PlayingState
ReadyState
Find out more at State (refactoring.guru)