Revision Notes/Design Patterns
Field Entry - Design Patterns
Factory Method Pattern
Defines an interface for creating objects but lets subclasses or implementations decide which class to instantiate.
Field Note - Real-world Analogy
“Think of a restaurant kitchen. You (the client) say "I want a pizza" and the kitchen (factory) decides which chef to call and how to make it. You don't go into the kitchen and mix dough yourself — you just order and the factory produces the result.”
Field Observations - Key Topics Covered
The problem Factory solves: imagine you have code that needs to create different types of objects (like Circle, Square, Triangle) based on some condition. Without Factory, you end up with huge if-else or switch-case blocks spread everywhere in your code. Every time you add a new shape, you have to find and update all those places.
4 more observations inside
Sign in to read every key point in full
Ready to go deeper?
Open the complete revision note.
Sign in to read every field observation in full, including a runnable code example and side-by-side comparisons with related patterns.
Read Full NotesSee Also in Design Patterns