Which of the following is the most accurate description of SOLID principles?
Tools for automatically generating code
Strict rules that must be followed in all programming scenarios
Advanced design patterns for specific software architectures
Guidelines that help write more maintainable and scalable software
How do SOLID principles contribute to reducing code complexity?
By enforcing strict coding standards
By encouraging the use of design patterns
By promoting modular and decoupled code
By promoting shorter code
Imagine a class named 'Employee' that handles both employee data (like name, ID) and database operations. What SOLID principle does this violate?
Liskov Substitution Principle
Single Responsibility Principle
Interface Segregation Principle
Open/Closed Principle
Which of these scenarios indicates a violation of the Interface Segregation Principle?
A single interface defines methods for both printing and saving a document.
A class implements multiple interfaces to achieve polymorphism.
An interface is used to abstract the creation of objects.
A class inherits from an abstract base class and overrides its methods.
In the context of the Open/Closed Principle, what does 'open for extension' mean?
The source code of a class should always be accessible for any developer to modify.
All classes should be loosely coupled and easily replaceable.
A class's behavior should be modifiable through inheritance or polymorphism.
Code should be heavily commented to explain every detail.
How does using interfaces contribute to the Open/Closed Principle?
Interfaces make code execution slower.
Interfaces allow for direct modification of existing class code.
Interfaces force tight coupling between classes.
Interfaces define a contract that can be implemented by multiple classes, enabling flexibility.
How does DIP help make code more maintainable?
By reducing the number of classes needed
By reducing the need for comments
By making it easier to test modules in isolation
By making classes smaller
Which of the following best describes the Dependency Inversion Principle (DIP)?
Low-level modules should depend on high-level modules.
High-level modules should depend on low-level modules.
Abstractions should depend on concrete implementations.
Both high-level and low-level modules should depend on abstractions.
Which of these is NOT a benefit commonly associated with applying the Dependency Inversion Principle?
Reduced code coupling
Enhanced code reusability
Improved testability
Increased code complexity
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 are only applicable to abstract classes, not interfaces.
They are specific to how a particular client uses a class, regardless of its primary responsibility.
They violate the Single Responsibility Principle.