Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 ?

like image 305
anth Avatar asked Nov 11 '11 19:11

anth


People also ask

What is difference between single responsibility and interface segregation?

SRP tells us that you should only have a single responsibility in a module. ISP tells us that you should not be forced to be confronted with more than you actually need. If you want to use a print() method from interface I , you shouldn't have to instantiate a SwimmingPool or a DriveThru class for that.

What is interface segregation in SOLID principles?

In the field of software engineering, the interface segregation principle (ISP) states that no code should be forced to depend on methods it does not use. ISP splits interfaces that are very large into smaller and more specific ones so that clients will only have to know about the methods that are of interest to them.

Why is the Interface Segregation Principle important?

In this article, we took a detailed look at the Interface Segregation Principle which Robert C. Martin defined as: “Clients should not be forced to depend upon interfaces that they do not use.” By following this principle, you prevent bloated interfaces that define methods for multiple responsibilities.

Which is correct related to the single responsibility principle?

The single-responsibility principle (SRP) is a computer programming principle that states that "A module should be responsible to one, and only one, actor." The term actor refers to a group (consisting of one or more stakeholders or users) that requires a change in the module. Robert C.


1 Answers

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.

like image 174
Andreas Hallberg Avatar answered Sep 22 '22 15:09

Andreas Hallberg