Which of the following best describes the impact of SRP on code testability?
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 impossible to write unit tests as it encourages separation of concerns.
SRP makes it more complex to write unit tests as classes have intertwined functionalities.
How does the Interface Segregation Principle relate to the idea of 'programming to an interface, not an implementation'?
ISP helps achieve the flexibility of using different implementations by keeping interfaces minimal and focused on client needs.
ISP contradicts this idea by promoting the use of concrete classes.
They are unrelated concepts in software design.
ISP only applies to statically typed languages, while 'programming to an interface' is a dynamic language concept.
How does the Interface Segregation Principle contribute to loose coupling in software design?
By promoting the use of concrete classes instead of interfaces.
By minimizing dependencies between classes to only what is absolutely necessary.
By encouraging the use of global variables for communication between classes.
By reducing the need for unit testing.
Imagine a class named 'Employee' that handles both employee data (like name, ID) and database operations. What SOLID principle does this violate?
Liskov Substitution Principle
Interface Segregation Principle
Single Responsibility Principle
Open/Closed Principle
How can you identify multiple responsibilities within a class?
By looking for different reasons to change the class in the future.
By observing how many other classes it interacts with.
By counting the number of lines of code in the class.
By checking if the class name is too long.
Which of these techniques can help achieve the Open/Closed Principle?
Avoiding the use of design patterns.
Copying and pasting code to create new functionality.
Using abstract classes and interfaces.
Hardcoding values directly into classes.
Which of these is NOT a potential consequence of violating the Liskov Substitution Principle?
Improved performance due to optimized subclass implementations.
Higher likelihood of introducing bugs when extending or modifying code.
Increased code complexity and reduced readability.
Decreased code reusability as subclasses may not behave as expected.
What could be a potential downside of excessively applying the Interface Segregation Principle?
It can lead to a higher number of interfaces, potentially increasing code complexity.
It reduces code reusability.
It makes the code more difficult to unit test.
It violates the principles of object-oriented programming.
How can you identify potential violations of the Liskov Substitution Principle in your code?
By looking for instances where a subclass throws an exception not declared in the superclass or introduces behavior that breaks the superclass's contract.
By ensuring all methods in subclasses are static.
By avoiding inheritance altogether and favoring composition.
By only using abstract classes and interfaces.
In the context of ISP, why are 'role interfaces' considered good practice?
They define a broad set of methods used by many unrelated classes.
They are specific to how a particular client uses a class, regardless of its primary responsibility.
They violate the Single Responsibility Principle.
They are only applicable to abstract classes, not interfaces.