The “I” in solid.

The Interface Segregation Principle (ISP) states that clients should not be forced to depend on methods that they do not use. Many times we use Abstract base classes or interfaces to define methods and variables that should be used by client classes.

There are cases when a client doesn’t need to use a specific method but since its already used in other client classes, we opt we declare the function but don’t implement it. This violates the Interface Segregation Principle. I have been violating this principle many times and never bothered to research because, at the end of the day, the code still works. To have clean, readable and “necessary” code, A developer has to put in mind the five S.O.L.I.D principles, in this case, the “I”.

The workaround for this would be to create an interface for that specific client. so instead of creating one giant interface, you could have a base interface with the basic functionality used by all clients, the create other interfaces that inherit from the base interface so that if we have a class with advanced features, we give it it's own interface.

Previous
Previous

Open-Closed Principle

Next
Next

April 10th 2020 -Developing on existing codebase.