Mid
From PDF
SOLID
Design Patterns & SOLID
Can you explain the difference between Abstract Factory and Builder patterns with examples?
Short answer: Abstract Factory: Provides an interface for creating families of related objects without specifying concrete classes.
Example code
Creating UI components for different OS (Windows, Mac). Builder: Focuses on step-by-step construction of a complex object, allowing different representations. Example: Building a complex House with various parts (walls, doors, roof). Summary: Abstract Factory is about families of products, Builder is about complex construction process.
Real-world example (ShopNest)
ShopNest payment fees use Strategy: IFeeCalculator with UPI/Card implementations chosen at runtime.
Say this in the interview
- Define — one clear sentence (the short answer above).
- Example — relate it to a project like ShopNest or your real work.
- Trade-off — when you would not use it.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png