Bird
Raised Fist0

You have a class that handles user authentication and also formats user profile data for display. According to the Single Responsibility Principle (SRP), what is the best design approach?

easy🔍 Pattern Recognition Q1 of Q15
OOP & Design Patterns - Single Responsibility Principle - One Class, One Reason to Change
You have a class that handles user authentication and also formats user profile data for display. According to the Single Responsibility Principle (SRP), what is the best design approach?
AKeep both responsibilities in one class since they relate to the user domain.
BSeparate authentication and profile formatting into two classes because they have different reasons to change.
CCombine authentication with any user-related functionality to reduce the number of classes.
DMerge profile formatting with UI rendering classes to improve cohesion.
Step-by-Step Solution
Solution:
  1. Step 1: Identify distinct reasons to change

    Authentication logic changes when security policies evolve; profile formatting changes when UI requirements change. These are separate reasons to change.
  2. Step 2: Apply SRP

    SRP states one class should have only one reason to change, so responsibilities should be separated.
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    Authentication and formatting have different change triggers [OK]
Quick Trick: One reason to change means one responsibility per class [OK]
Common Mistakes:
MISTAKES
  • Assuming related domain means one responsibility
  • Merging unrelated concerns to reduce class count
Trap Explanation:
PITFALL
  • Candidates often think related domain logic belongs in one class, ignoring distinct change reasons.
Interviewer Note:
CONTEXT
  • Tests understanding of SRP's core definition and reasoning about change triggers.
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