Junior — Middle
Which SOLID principle might be violated if one object is responsible for too many tasks?
sobes.tech AI
Answer from AI
If one object is responsible for too many tasks, the Single Responsibility Principle (SRP) from the SOLID set is violated.
SRP states that a class should have only one reason to change, meaning it should have only one responsibility. Violating this principle leads to complex, hard-to-maintain, and testable code.
For example, if a class simultaneously handles business logic, manages database access, and is responsible for output formatting, this is a sign of SRP violation. It is better to split these responsibilities into separate classes, each responsible for its own task.