Bird
Raised Fist0

You are designing a system that manages user accounts and sends notification emails. According to the Single Responsibility Principle, how should you organize these responsibilities?

easy🔍 Pattern Recognition Q11 of Q15
OOP & Design Patterns - Single Responsibility Principle - One Class, One Reason to Change
You are designing a system that manages user accounts and sends notification emails. According to the Single Responsibility Principle, how should you organize these responsibilities?
ASeparate user account management and email notification into different classes because each has a different reason to change.
BCombine user account management and email notification in one class because they are related to users.
CPut all user-related functionalities, including notifications, into a single class to reduce the number of classes.
DCreate one class for user management and embed email notification logic inside its methods to simplify interactions.
Step-by-Step Solution
  1. Step 1: Identify reasons to change

    User account management changes when user data or authentication changes; email notifications change when messaging or delivery requirements change.
  2. Step 2: Apply SRP

    Since these reasons to change differ, they should be separated into different classes to avoid coupling unrelated changes.
  3. Step 3: Evaluate other options

    Options A, C, and D combine responsibilities, increasing coupling and reducing cohesion, violating SRP.
  4. Final Answer:

    Option A -> Option A
  5. Quick Check:

    Separate classes for distinct reasons to change -> SRP compliant.
Quick Trick: One class, one reason to change.
Common Mistakes:
MISTAKES
  • Assuming related domain means same responsibility.
  • Combining functionalities to reduce class count.
  • Embedding multiple responsibilities for convenience.
Trap Explanation:
PITFALL
  • Options that group related domain logic but different reasons to change seem simpler but violate SRP by coupling unrelated changes.
Interviewer Note:
CONTEXT
  • Tests candidate's ability to recognize when SRP applies in design decisions.
Master "Single Responsibility Principle - One Class, One Reason to Change" 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