Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions notes/08-observer-strategy.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ The two approaches we have discussed so far are not ideal. The first approach vi
1. `Observable interface` - This interface defines the methods that the subject class must implement. The subject class is responsible for notifying the observers when the state of the subject changes.

```java
public interface class Observable {
public interface Observable {
void addObserver(Observer observer);
void removeObserver(Observer observer);
void notifyObservers();
Expand All @@ -100,7 +100,7 @@ public interface class Observable {
2. `Observer interface` - This interface defines the methods that the observer class must implement. The observer class is responsible for updating itself when the state of the subject changes.

```java
public interface class Observer {
public interface Observer {
void notify();
}
```
Expand Down Expand Up @@ -279,4 +279,4 @@ To create a strategy object we can also use a factory method.
* Implementing it in place violates the open-closed principle and makes the code harder to maintain.
* Inheritance is static, and we cannot change the behavior of the system at runtime.
* To use the strategy pattern we create a strategy interface and a set of classes that implement it.
* The context class maintains a reference to a strategy object and delegates the work to it.
* The context class maintains a reference to a strategy object and delegates the work to it.