Design Patterns - Examples
Design Patterns - Examples
Design Patterns
Façade
Singleton
Adapter
Factory Method
Abstract Factory
Chain of Responsibility
FACADE
Façade
Façade -Example
Façade - Example
Façade- Example
Singleton
Singleton
Singleton – Logger
Problem- Solution-
If your program needs to do
logging, you may want all output With a singleton logger object, you don’t need
to be written to one log file. That to worry about several different objects trying
could lead to resource conflicts to write to the same file, at the same time.
and errors.
Logger - Example
Logger – Client Class(s)
Adapter
Adapter – Object Adapter
Adapter – Class Adapter
Adapter - Example
Let’s say we have a ShopInventory which maintains a list of products. Later on, we
took over another store inventory which sells groceries. We now want to add those
items to our ShopInventory. The problem we have here is that although
the GroceryItem is just a type of product but is unrelated to the Product interface.
Adapter -Example
Adapter- Example
Factory Method
Factory Method
Factory Method- Example
Factory Method
Factory Method - Example
Factory Method -Usage