Behavioral Design Patterns


Strategy Pattern

Screenshot 2020-12-12 at 9.37.23 AM

Screenshot 2020-12-12 at 9.24.32 AM

Code Explanation:

Strategy.java

Screenshot 2020-12-12 at 9.25.24 AM

OperationAdd.java

Screenshot 2020-12-12 at 9.28.24 AM

OperationSubtract.java

Screenshot 2020-12-12 at 9.29.58 AM

OperationMultiply.java

Screenshot 2020-12-12 at 9.30.49 AM

Context.java

Screenshot 2020-12-12 at 9.31.37 AM

StrategyPatternDemo.java

Screenshot 2020-12-12 at 9.33.12 AM


Observer Pattern

Screenshot 2020-12-12 at 9.36.41 AM

Screenshot 2020-12-12 at 9.41.28 AM

Note:- Observers are subscribed to subject and have one to many relationships and whenever subject publishes observers gets notifications. It follows push based approach and whenever they have something they push to the observers.