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.
What is a key benefit of adhering to the Interface Segregation Principle?
Increased code reusability.
Improved code flexibility and maintainability.
Reduced code duplication.
All of the above.
What is the core idea behind the Liskov Substitution Principle (LSP)?
Interfaces should be small and focused on a single task.
Classes should have only one responsibility.
Subtypes should be substitutable for their base types without altering the correctness of the program.
Code should be open for extension, but closed for modification.
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()
Keep the current design, as it provides a single point of access for all communication methods.
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.
How can you identify potential violations of the Liskov Substitution Principle in your code?
By ensuring all methods in subclasses are static.
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 avoiding inheritance altogether and favoring composition.
By only using abstract classes and interfaces.
Why might strictly adhering to the Open/Closed Principle in every single part of a codebase be impractical?
It makes the codebase less secure.
It violates other SOLID principles.
It can lead to over-engineering and unnecessary complexity in some cases.
It simplifies the design too much.
SOLID principles primarily aim to improve which aspect of software development?
Execution Speed
Memory Optimization
Algorithm Efficiency
Code Maintainability
In a layered application, which layer typically contains the high-level modules according to DIP?
Business Logic Layer
Database Layer
Presentation Layer
Data Access Layer
Why is the Open/Closed Principle important in software development?
It makes code less readable.
It increases the risk of introducing bugs during modification.
It complicates the development process.
It promotes code duplication.
Why is adhering to the Liskov Substitution Principle important in software development?
It helps reduce the number of lines of code.
It ensures that all methods have the same name across different classes.
It promotes code reusability, maintainability, and reduces the risk of unexpected bugs when modifying code.
It enforces the use of design patterns, making code more readable.