What is a potential drawback of NOT following SRP?
The codebase becomes more difficult to maintain and prone to bugs.
Changes in one part of the code are less likely to affect other parts.
Classes become more reusable and easier to understand.
Classes become more focused and have a clearer purpose.
Which of these is NOT a benefit commonly associated with applying the Dependency Inversion Principle?
Increased code complexity
Enhanced code reusability
Improved testability
Reduced code coupling
Why might strictly adhering to the Open/Closed Principle in every single part of a codebase be impractical?
It makes the codebase less secure.
It simplifies the design too much.
It violates other SOLID principles.
It can lead to over-engineering and unnecessary complexity in some cases.
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()
Keep the current design, as it provides a single point of access for all communication methods.
Throw an exception in EmailService for the unused methods: sendSMS() and 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
How can you identify multiple responsibilities within a class?
By observing how many other classes it interacts with.
By looking for different reasons to change the class in the future.
By checking if the class name is too long.
By counting the number of lines of code in the class.
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.
Code should be heavily commented to explain every detail.
All classes should be loosely coupled and easily replaceable.
A class's behavior should be modifiable through inheritance or polymorphism.
Which of these techniques can help achieve the Open/Closed Principle?
Copying and pasting code to create new functionality.
Hardcoding values directly into classes.
Avoiding the use of design patterns.
Using abstract classes and interfaces.
Which of these is NOT a valid approach to refactor a class violating SRP?
Delegate responsibilities to other existing classes.
Use design patterns like Strategy or Template Method to separate concerns.
Extract separate functionalities into new classes.
Combine all the responsibilities into a single method for better cohesion.
Which scenario best exemplifies the Dependency Inversion Principle?
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.
A 'Logger' class writes logs directly to a file.
How does using interfaces contribute to the Open/Closed Principle?
Interfaces force tight coupling between classes.
Interfaces define a contract that can be implemented by multiple classes, enabling flexibility.
Interfaces make code execution slower.
Interfaces allow for direct modification of existing class code.