Design

Object-Oriented Design (OOD): Key Insights

Step 1: Handle Ambiguity

  • OOD questions are often intentionally vague to test your ability to clarify requirements.
  • Ask Clarifying Questions:
    • Use β€œwho, what, when, where, why, how” to define complexity and scope.
    • Avoid making assumptions; probe for details about the system’s functionality and constraints.

Step 2: Define Core Objects

  • Identify the primary components of the system.
  • Example for a restaurant system:
    • Objects: Table, Guest, Party, Order, Meal, Employee, Server, Host.

Step 3: Analyze Relationships

  • Determine how objects relate to one another:
    • Which objects are members of other objects?
    • Do any objects inherit from others?
    • Are relationships one-to-many or many-to-many?

Step 4: Investigate Actions

  • Identify the key actions each object will perform and how they interact.
  • Translate these actions into methods for the respective objects.

Common Design Patterns

Singleton

  • Purpose: Ensures a class has only one instance, accessible globally.
  • Drawbacks: Often considered an β€œanti-pattern” as it can complicate unit testing and introduce hidden dependencies.

Factory Method

  • Purpose: Provides a way to create an instance of a class, letting subclasses decide which specific class to instantiate.
  • Benefit: Promotes flexibility and reduces coupling between objects.