Bird
Raised Fist0

If the formatting requirements change often but the database schema remains stable, what is the expected consequence when applying the Single Responsibility Principle?

easy🧾🤔 Trace Reasoning Q3 of Q15
OOP & Design Patterns - Single Responsibility Principle - One Class, One Reason to Change
A class is responsible for both formatting user input and saving it to a database. If the formatting requirements change often but the database schema remains stable, what is the expected consequence when applying the Single Responsibility Principle?
AThe class will become more complex as responsibilities are combined.
BBoth formatting and database classes must be changed simultaneously.
CThe database schema will need frequent updates to accommodate formatting changes.
DOnly the formatting class needs modification, leaving the database class unaffected.
Step-by-Step Solution
Solution:
  1. Step 1: Identify responsibilities

    The class has two responsibilities: formatting input and saving data.
  2. Step 2: Apply SRP

    Separate these into two classes: one for formatting, one for persistence.
  3. Step 3: Analyze impact of changes

    When formatting rules change, only the formatting class requires modification; the persistence class remains stable.
  4. Final Answer:

    Option D -> Option D
  5. Quick Check:

    Separate responsibilities isolate changes [OK]
Quick Trick: Separate concerns to isolate changes [OK]
Common Mistakes:
MISTAKES
  • Assuming database changes with formatting updates
  • Believing both responsibilities must be changed together
  • Thinking combining responsibilities reduces complexity
Trap Explanation:
PITFALL
  • Option B looks plausible because both responsibilities are in one class, but SRP separates them.
Interviewer Note:
CONTEXT
  • Tests understanding of how SRP isolates changes to specific responsibilities.
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