Clean Architecture – Chapter 10 | ISP | Interface Segregation Principle

So far we have gone through Single Responsibility Principle and Open Closed Principle , Liskov Substitution Principle, which cover three SOLID principles. In this post, we will go through I ie Interface Segregation Principle. 

Let’s go through an example to understand this principle. 

Let’s say OPS class has three operations op1, op2, and op3. And there are three users, User1 uses op1, User2 uses op2, User3 uses op3 . If there is change in op3, both User1 and User2 will have to recompile and redeploy their code. 

Now instead if each of these operations are segregated into three different interfaces and each user just depends on their interface, then if there is change in op3, only user3 will need to recompile and redeploy their code. This is called Interface Segregation Principle. 

 

ISP and Languages

In statically typed languages like Java, with statements like import, include, use, etc, create source code dependencies, that force recompilation and redeployment and so ISP becomes necessary.

In dynamically typed languages, where declarations does not exists, but inferred at runtime, there are no source code dependencies, that force recompilation and redeployment. This is primary reason systems with dynamically typed languages are more flexible and less tightly coupled.

ISP and Architecture

ISP is just not language level restriction. But it is also relevant at architecture level. It is harmful to depend on a module that contains more than you need. 

For example, you are architecting a system, and you decide to use a framework that depends on a database. If there is change in the database, both the framework and your system would need to recompile and redeploy. Or if any feature in the database fails, it will call failure in both the framework and your system. 

The lesson is depending on something that carries extra baggage that we don’t need can cause us trouble that we don’t expect.

Thanks for stopping by! I hope this gives a good preview into ISP. Eager to hear your thoughts and chat, please leave comments below and we can discuss.