You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Imad laghrissi edited this page Oct 8, 2019
·
3 revisions
Design patterns
1. Singleton pattern
- change visibility of constructor to private in order to prevent the creation of multiple instances.
- Declare a static instance in the class.
- Create static method that will return the instance.
2. Factory method pattern
- Create an interface that will be implemented by differents classes.
- Create differents classes to implement the interface.
- Create factory classe to get instance by passing the instance type.
3. Decorator pattern
This pattern allows you to add new functionality to an existing object without changing its structure.
- Create an interface that will be implemented by differents classes.
- Create differents classes to implement the interface.
- Create abstract class implement the interface in order to override methods .
- Create decorator class to extends this abstract class which wraps the original class and provides additional functionality keeping class methods signature intact.