Which of these is a benefit of adhering to the Single Responsibility Principle?
Increased class size for better code organization.
Tighter coupling between classes for better collaboration.
More complex class design for handling multiple tasks.
Reduced code duplication and improved reusability.
In a layered application, which layer typically contains the high-level modules according to DIP?
Database Layer
Business Logic Layer
Data Access Layer
Presentation Layer
Which of the following is a direct benefit of applying SOLID principles?
Reduced need for documentation
Guaranteed bug-free software
Faster initial development speed
Improved code reusability and extensibility
How does the Interface Segregation Principle contribute to loose coupling in software design?
By reducing the need for unit testing.
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.
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?
Remove the 'fly()' method from the 'Bird' class entirely.
Have 'Penguin' inherit 'fly()' but leave it empty, as penguins don't need to fly.
Have 'Penguin' inherit 'fly()' and throw an exception, as penguins cannot fly.
Rethink the inheritance hierarchy. 'Bird' might not be the right superclass for 'Penguin' if flying is a core characteristic.
How does SRP contribute to creating loosely coupled classes?
By promoting the use of global variables for shared data access.
By encouraging classes to have multiple responsibilities for better interaction.
By making classes dependent on each other for core functionalities.
By reducing the points of interaction between classes as they have focused roles.
Which of these scenarios indicates a violation of the Interface Segregation Principle?
An interface is used to abstract the creation of objects.
A class inherits from an abstract base class and overrides its methods.
A single interface defines methods for both printing and saving a document.
A class implements multiple interfaces to achieve polymorphism.
How does DIP relate to the concept of 'inversion of control'?
Inversion of control is a specific implementation of DIP.
DIP is a specific implementation of inversion of control.
DIP and inversion of control are the same thing.
They are unrelated concepts.
What is the core idea behind the Single Responsibility Principle (SRP)?
A class should have a single, well-defined responsibility.
A class should be as small as possible.
A class should interact with as few other classes as possible.
A class should have only one method.
A class EmailService implements an interface ICommunication with methods sendEmail(), sendSMS(), and makeCall(). Only the email functionality is relevant to EmailService. How can this design be improved according to ISP?
EmailService
ICommunication
sendEmail()
sendSMS()
makeCall()
Throw an exception in EmailService for the unused methods: sendSMS() and makeCall().
Create separate interfaces: IEmailService, ISMSService, and ICallService, and have EmailService implement only IEmailService.
IEmailService
ISMSService
ICallService
Move all methods (sendEmail(), sendSMS(), makeCall()) to the EmailService class.
Keep the current design, as it provides a single point of access for all communication methods.