Behavioral Design Patterns
Behavioral Design Patterns
For Example Company updates all its shareholders for any decision they make here Company is Subject and Shareholders are Observers, any change in policy of company and Company notifies all its Shareholders or Observer.
Another Example is when you have a Loan on which interest rate is subject to change and on change, Loan notifies to Newspaper or Internet media to display new loan interest rate. To implement this we have a Subject interface which contains methods for adding, removing and notifying Observers and an Observer interface which contains update(int interest) method which will be called by Subject implementation when interest rate changes.
Situation: A GUI container object wants to decide at run-time what strategy it should use to layout the GUI components it contains. Many different layout strategies are already available. Solution: Encapsulate the different layout strategies using the Strategy pattern!
Use Template Method Pattern To implement the invariant part of an algorithm, and leave it up to subclasses to implement the part that can vary. When common code in subclasses should be factored and localized in a common base class to avoid code duplication. To control extensions to subclasses.
An iterator pattern can be used when one class is a collection of things and would like to provide a standardized method of accessing its collection to another class.
Provides a way to access elements of a collection object sequentially without exposing its underlying representation. The iterator object takes the responsibility of traversing a collection away from collection object. This simplifies the collection interface and implementation.
Thank you