Which of these is NOT a potential consequence of violating the Liskov Substitution Principle?
Improved performance due to optimized subclass implementations.
Increased code complexity and reduced readability.
Higher likelihood of introducing bugs when extending or modifying code.
Decreased code reusability as subclasses may not behave as expected.
How does inheritance relate to the Liskov Substitution Principle?
Inheritance is a prerequisite for applying LSP; it guides the correct implementation of inheritance.
LSP only applies when using multiple interfaces, not inheritance.
LSP dictates that all classes must inherit from a single base class.
Inheritance has no direct relationship with LSP.
Which scenario best exemplifies the Dependency Inversion Principle?
A 'Logger' class writes logs directly to a file.
A 'LightSwitch' class is directly dependent on a 'LightBulb' class.
A 'DataProcessor' class depends on an 'IDataSource' interface, not a specific database implementation.
A 'Car' class directly instantiates and uses an 'Engine' class.
The Liskov Substitution Principle primarily deals with the relationship between:
Interfaces and their implementations
Subclasses and their superclasses
All of the above
Classes and their instances
What is a potential drawback of NOT following SRP?
Changes in one part of the code are less likely to affect other parts.
Classes become more focused and have a clearer purpose.
Classes become more reusable and easier to understand.
The codebase becomes more difficult to maintain and prone to bugs.
How does using interfaces contribute to the Open/Closed Principle?
Interfaces force tight coupling between classes.
Interfaces allow for direct modification of existing class code.
Interfaces define a contract that can be implemented by multiple classes, enabling flexibility.
Interfaces make code execution slower.
How do SOLID principles contribute to reducing code complexity?
By promoting modular and decoupled code
By enforcing strict coding standards
By encouraging the use of design patterns
By promoting shorter code
What is the core idea behind the Liskov Substitution Principle (LSP)?
Interfaces should be small and focused on a single task.
Code should be open for extension, but closed for modification.
Classes should have only one responsibility.
Subtypes should be substitutable for their base types without altering the correctness of the program.
Which of the following best describes the Dependency Inversion Principle (DIP)?
Abstractions should depend on concrete implementations.
Low-level modules should depend on high-level modules.
High-level modules should depend on low-level modules.
Both high-level and low-level modules should depend on abstractions.
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 violate the Single Responsibility Principle.
They are only applicable to abstract classes, not interfaces.
They are specific to how a particular client uses a class, regardless of its primary responsibility.