Search code examples
design-patternssolid-principlessingle-responsibility-principleinterface-segregation-principle

Is Interface segregation principle only a substitue for Single responsibility principle?


Is interface segregation principle only a substitue for single responsibility principle ?

I think that if my class fulfill SRP there is no need to extract more than one interface.

So ISP looks like solution in case we have to break SRP for some reason.

Am I right ?


Solution

  • No. Take the example of a class whose responsibility is persisting data on e.g. the harddrive. Splitting the class into a read- and a write part would not make practical sense. But some clients should only use the class to read data, some clients only to write data, and some to do both. Applying ISP here with three different interfaces would be a nice solution.