How does the Interface Segregation Principle contribute to loose coupling in software design?
By encouraging the use of global variables for communication between classes.
By minimizing dependencies between classes to only what is absolutely necessary.
By promoting the use of concrete classes instead of interfaces.
By reducing the need for unit testing.
What is the core idea behind the Liskov Substitution Principle (LSP)?
Classes should have only one responsibility.
Interfaces should be small and focused on a single task.
Code should be open for extension, but closed for modification.
Subtypes should be substitutable for their base types without altering the correctness of the program.
What is the core idea behind the Interface Segregation Principle (ISP)?
Code should be open for extension but closed for modification.
Subclasses should be substitutable for their base classes.
Clients should not be forced to depend on methods they don't use.
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.
How does inheritance relate to the Liskov Substitution Principle?
Inheritance is a prerequisite for applying LSP; it guides the correct implementation of inheritance.
LSP dictates that all classes must inherit from a single base class.
LSP only applies when using multiple interfaces, not inheritance.
Inheritance has no direct relationship with LSP.
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.
How does the Open/Closed Principle contribute to creating maintainable code?
It makes the codebase smaller.
It eliminates the need for testing.
It reduces the need for code documentation.
It allows for easier addition of new features without impacting existing ones.
In the context of DIP, what are abstractions typically represented by?
Database connections
Interfaces or abstract classes
Concrete classes
User interface components
Why might strictly adhering to the Open/Closed Principle in every single part of a codebase be impractical?
It can lead to over-engineering and unnecessary complexity in some cases.
It violates other SOLID principles.
It simplifies the design too much.
It makes the codebase less secure.
The Liskov Substitution Principle primarily deals with the relationship between:
All of the above
Interfaces and their implementations
Classes and their instances
Subclasses and their superclasses