What is a potential drawback of NOT following SRP?
The codebase becomes more difficult to maintain and prone to bugs.
Changes in one part of the code are less likely to affect other parts.
Classes become more reusable and easier to understand.
Classes become more focused and have a clearer purpose.
What is a key benefit of adhering to the Interface Segregation Principle?
Reduced code duplication.
Improved code flexibility and maintainability.
Increased code reusability.
All of the above.
Which of these is NOT a potential consequence of violating the Liskov Substitution Principle?
Decreased code reusability as subclasses may not behave as expected.
Increased code complexity and reduced readability.
Higher likelihood of introducing bugs when extending or modifying code.
Improved performance due to optimized subclass implementations.
Which of these is NOT a valid approach to refactor a class violating SRP?
Delegate responsibilities to other existing classes.
Extract separate functionalities into new classes.
Combine all the responsibilities into a single method for better cohesion.
Use design patterns like Strategy or Template Method to separate concerns.
Which of these techniques can help achieve the Open/Closed Principle?
Copying and pasting code to create new functionality.
Avoiding the use of design patterns.
Using abstract classes and interfaces.
Hardcoding values directly into classes.
Which of these scenarios indicates a violation of the Interface Segregation Principle?
A single interface defines methods for both printing and saving a document.
A class implements multiple interfaces to achieve polymorphism.
An interface is used to abstract the creation of objects.
A class inherits from an abstract base class and overrides its methods.
Which of the following best describes the impact of SRP on code testability?
SRP makes it impossible to write unit tests as it encourages separation of concerns.
SRP makes unit testing easier as classes are smaller and have well-defined responsibilities.
SRP has no significant impact on the ease or difficulty of writing unit tests.
SRP makes it more complex to write unit tests as classes have intertwined functionalities.
How does using interfaces contribute to the Open/Closed Principle?
Interfaces force tight coupling between classes.
Interfaces allow for direct modification of existing class code.
Interfaces make code execution slower.
Interfaces define a contract that can be implemented by multiple classes, enabling flexibility.
What is the core idea behind the Single Responsibility Principle (SRP)?
A class should be as small as possible.
A class should have only one method.
A class should have a single, well-defined responsibility.
A class should interact with as few other classes as possible.
Imagine a class named 'Employee' that handles both employee data (like name, ID) and database operations. What SOLID principle does this violate?
Single Responsibility Principle
Open/Closed Principle
Interface Segregation Principle
Liskov Substitution Principle