Which of these is NOT a potential consequence of violating the Liskov Substitution Principle?
Increased code complexity and reduced readability.
Decreased code reusability as subclasses may not behave as expected.
Improved performance due to optimized subclass implementations.
Higher likelihood of introducing bugs when extending or modifying code.
Which of these is NOT a valid approach to refactor a class violating SRP?
Combine all the responsibilities into a single method for better cohesion.
Use design patterns like Strategy or Template Method to separate concerns.
Extract separate functionalities into new classes.
Delegate responsibilities to other existing classes.
How can SOLID principles impact team collaboration in software development?
By promoting a shared understanding of code structure and design
By automating code review processes
By enforcing strict coding style guidelines
By reducing the need for communication within the team
Which of these techniques can help achieve the Open/Closed Principle?
Avoiding the use of design patterns.
Using abstract classes and interfaces.
Hardcoding values directly into classes.
Copying and pasting code to create new functionality.
In the context of SRP, what does 'reason to change' mean?
A change in the application's requirements related to a specific functionality.
Refactoring the class for improved readability.
Any modification made to the class code.
Adding new features unrelated to the class's current responsibility.
Which of the following scenarios most likely violates the Liskov Substitution Principle?
A subclass throws an exception that is not declared in the superclass's method signature.
A subclass implements an interface that the superclass does not implement.
A subclass overrides a method of its superclass and provides additional functionality.
A subclass has more attributes than its superclass.
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()
Move all methods (sendEmail(), sendSMS(), makeCall()) to the EmailService class.
Create separate interfaces: IEmailService, ISMSService, and ICallService, and have EmailService implement only IEmailService.
IEmailService
ISMSService
ICallService
Throw an exception in EmailService for the unused methods: sendSMS() and makeCall().
Keep the current design, as it provides a single point of access for all communication methods.
Imagine an interface IWorker with methods work() and takeBreak(). You have two classes, Robot and Human, both implementing IWorker. How would you refactor this to better align with the ISP?
IWorker
work()
takeBreak()
Robot
Human
Make takeBreak() an abstract method within IWorker so only Human has to implement it.
Have Robot implement IWorker, but leave Human without an interface.
Keep the IWorker interface as is, as both classes can perform both actions.
Create two separate interfaces: IWorkable with work(), and IRest with takeBreak(). Implement them accordingly.
IWorkable
IRest
In the context of the Open/Closed Principle, what does 'open for extension' mean?
Code should be heavily commented to explain every detail.
A class's behavior should be modifiable through inheritance or polymorphism.
All classes should be loosely coupled and easily replaceable.
The source code of a class should always be accessible for any developer to modify.
Which of the following best describes the Dependency Inversion Principle (DIP)?
High-level modules should depend on low-level modules.
Abstractions should depend on concrete implementations.
Low-level modules should depend on high-level modules.
Both high-level and low-level modules should depend on abstractions.