Bird
Raised Fist0

Which design pattern best fits this requirement?

easy🔍 Pattern Recognition Q11 of Q15
OOP & Design Patterns - Factory vs Abstract Factory vs Builder - When to Use Each
You need to create different types of vehicles (cars, bikes) that share a common interface, and sometimes you want to create entire families of related vehicles (e.g., electric car + electric bike) ensuring consistency. Which design pattern best fits this requirement?
ABuilder Pattern, because it constructs complex objects step-by-step.
BAbstract Factory Pattern, because it creates families of related objects ensuring consistency.
CFactory Pattern, because it creates simple objects based on a type parameter.
DSingleton Pattern, because it ensures only one instance of each vehicle type.
Step-by-Step Solution
  1. Step 1: Understand the requirement for families of related objects

    The problem states the need to create related vehicles (e.g., electric car and electric bike) that belong to a family and must be consistent.
  2. Step 2: Match pattern to requirement

    Abstract Factory is designed to create families of related objects, ensuring that the created objects are compatible and consistent.
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    Abstract Factory creates related object families, Factory creates single objects [OK]
Quick Trick: Families of related objects -> Abstract Factory [OK]
Common Mistakes:
MISTAKES
  • Confusing Factory with Abstract Factory
  • Using Builder for simple object creation
Trap Explanation:
PITFALL
  • Factory creates single objects but does not guarantee family consistency, tempting candidates to pick it.
Interviewer Note:
CONTEXT
  • Tests candidate's ability to distinguish between Factory and Abstract Factory patterns.
Master "Factory vs Abstract Factory vs Builder - When to Use Each" in OOP & Design Patterns

2 interactive learning modes - each teaches the same concept differently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More OOP & Design Patterns Quizzes