4. I - Interface Segregation Principle (ISP)
“Clients should not be forced to depend on methods they do not use.”
ISP suggests splitting large, complex interfaces into smaller, more specific ones. This way, classes implementing an interface only need to be concerned with the methods relevant to them. By segregating interfaces, you make the code more flexible and avoid “fat” interfaces that force classes to implement unused methods.
Example: In a drawing app, rather than having one big Drawable interface with methods for drawCircle, drawSquare, drawTriangle, break it into smaller interfaces like CircleDrawable, SquareDrawable, etc., so classes only implement what they need. 0 reply
0 recast
0 reaction