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.