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

后端 未结 3 446
余生分开走
余生分开走 2021-02-01 17:06

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

3条回答
  •  太阳男子
    2021-02-01 17:35

    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.

提交回复
热议问题