How does the Interface Segregation Principle contribute to loose coupling in software design?
By promoting the use of concrete classes instead of interfaces.
By encouraging the use of global variables for communication between classes.
By reducing the need for unit testing.
By minimizing dependencies between classes to only what is absolutely necessary.
What is the primary purpose of the Open/Closed Principle?
To prevent modification of existing code
To enforce the use of abstract classes
To allow extending functionality without altering existing code
To ensure all methods are open for modification
How does SRP contribute to creating loosely coupled classes?
By making classes dependent on each other for core functionalities.
By promoting the use of global variables for shared data access.
By reducing the points of interaction between classes as they have focused roles.
By encouraging classes to have multiple responsibilities for better interaction.
Which scenario best exemplifies the Dependency Inversion Principle?
A 'Logger' class writes logs directly to a file.
A 'Car' class directly instantiates and uses an 'Engine' class.
A 'DataProcessor' class depends on an 'IDataSource' interface, not a specific database implementation.
A 'LightSwitch' class is directly dependent on a 'LightBulb' class.
Consider a base class 'Bird' with a method 'fly()'. You create a subclass 'Penguin'. What would be the most LSP-compliant approach in this scenario?
Have 'Penguin' inherit 'fly()' and throw an exception, as penguins cannot fly.
Have 'Penguin' inherit 'fly()' but leave it empty, as penguins don't need to fly.
Rethink the inheritance hierarchy. 'Bird' might not be the right superclass for 'Penguin' if flying is a core characteristic.
Remove the 'fly()' method from the 'Bird' class entirely.
In the context of LSP, what is meant by 'substitutability'?
The idea that all methods in a subclass should be static.
The ability to change the behavior of a superclass by modifying its subclass.
The practice of always using abstract classes instead of concrete classes.
The capability to use a subclass object wherever a superclass object is expected without causing issues.
SOLID principles primarily aim to improve which aspect of software development?
Code Maintainability
Execution Speed
Memory Optimization
Algorithm Efficiency
Consider a 'NotificationService' responsible for sending notifications. Which option violates DIP?
The 'NotificationService' accepts an 'INotificationChannel' in its constructor.
The 'NotificationService' directly instantiates and uses an 'EmailSender' class.
The 'NotificationService' depends on an 'INotificationChannel' interface.
Different channels like 'SMSChannel' implement the 'INotificationChannel' interface.
What is the core idea behind the Interface Segregation Principle (ISP)?
Subclasses should be substitutable for their base classes.
Classes should have only one responsibility.
Code should be open for extension but closed for modification.
Clients should not be forced to depend on methods they don't use.
How does the Interface Segregation Principle relate to the idea of 'programming to an interface, not an implementation'?
ISP contradicts this idea by promoting the use of concrete classes.
ISP only applies to statically typed languages, while 'programming to an interface' is a dynamic language concept.
They are unrelated concepts in software design.
ISP helps achieve the flexibility of using different implementations by keeping interfaces minimal and focused on client needs.