Login
Discover
Waves
Communities
Login
Signup
Factory Design Pattern
Factory Design Pattern
rakeshbecse
(25)
Published in
#softwaredesignpatterns
Words
0
Reading
0 min
Listen
Play
2018-04-01 04:48
Factory Design Pattern:
It falls under
Creational Design Pattern
.
Factory pattern says that object creation will be handled by another class using the input type.
Advantages:
It allows loose-coupling.
When to use Factory Design Pattern?
Factory design pattern is used when we have a superclass with multiple sub-classes and based on the input, we need to return one of the sub-class.
Example: If a Restaurant serves Veg food, Non-Veg food, and Italian food.
Treat VegFood, NonVegFood, and ItalianFood as three classes whose superclass is Food.
If a customer asks "Veg" then Factory method would return the "VegFood" class.
Read next
Learn Python Series (#45) - Metaclasses & Class Design Patterns
Hospitality Interior Design: Creating Modern and Memorable Guest Experiences
Welcoming Summer Break- Treating Kids Fried Chicken and Spaghetti