How do SOLID principles contribute to reducing code complexity?
By promoting shorter code
By enforcing strict coding standards
By promoting modular and decoupled code
By encouraging the use of design patterns
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 'LightSwitch' class is directly dependent on a 'LightBulb' class.
A 'DataProcessor' class depends on an 'IDataSource' interface, not a specific database implementation.
How does inheritance relate to the Liskov Substitution Principle?
Inheritance is a prerequisite for applying LSP; it guides the correct implementation of inheritance.
Inheritance has no direct relationship with LSP.
LSP only applies when using multiple interfaces, not inheritance.
LSP dictates that all classes must inherit from a single base class.
What is the core idea behind the Liskov Substitution Principle (LSP)?
Subtypes should be substitutable for their base types without altering the correctness of the program.
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.
Which of these is NOT a benefit commonly associated with applying the Dependency Inversion Principle?
Enhanced code reusability
Increased code complexity
Reduced code coupling
Improved testability
Which of the following best describes the Dependency Inversion Principle (DIP)?
Both high-level and low-level modules should depend on abstractions.
Abstractions should depend on concrete implementations.
Low-level modules should depend on high-level modules.
High-level modules should depend on low-level modules.
Which of these is a benefit of adhering to the Single Responsibility Principle?
Reduced code duplication and improved reusability.
Increased class size for better code organization.
More complex class design for handling multiple tasks.
Tighter coupling between classes for better collaboration.
In the context of LSP, what is meant by 'substitutability'?
The practice of always using abstract classes instead of concrete classes.
The ability to change the behavior of a superclass by modifying its subclass.
The capability to use a subclass object wherever a superclass object is expected without causing issues.
The idea that all methods in a subclass should be static.
How can you identify potential violations of the Liskov Substitution Principle in your code?
By only using abstract classes and interfaces.
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 ensuring all methods in subclasses are static.
By avoiding inheritance altogether and favoring composition.
The Liskov Substitution Principle primarily deals with the relationship between:
Subclasses and their superclasses
Interfaces and their implementations
All of the above
Classes and their instances