Please enable JavaScript.
Coggle requires JavaScript to display documents.
Foundation- Design Patterns (04- Singleton (one instance of a class,…
Foundation- Design Patterns
01- Strategy
Inheritance is good but shouldnt be overused
Identify what changes in you class, specially methods/actions
create interface class for all behaviors which vary, then implement the concrete behaviors in separate classes
02- Observer
Publisher n subscriber example
Defines one-to-many relationship
Subject-dependent anology
03- Decorator
Open-closed principle
04- Singleton
one instance of a class
constructor is private
multi threading issues needs to be addressed
use synchronized block or create the instance while initializing the variable
05- State
Each state can have its own class
encapsulate state code which varies into separate classes
Favor composition over inheritance
classes are closed for modification but open for extension
06- The collection
07- Factory
Encapsulate object creation code
Encapsulate what vary - Identify the aspect of your code that vary and separate them from what vary
Program to an interface, not an implementation
Favor composition over inheritance
Strive for loosely coupled designs between objects that interact
Classes should be open for extension but closed for modification
The class should have only one reason to change