界面隔离原则只是一个单一责任原则的替代品? [英] Is Interface segregation principle only a substitue for Single responsibility principle?

查看:159
本文介绍了界面隔离原则只是一个单一责任原则的替代品?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

接口隔离原理只是一个单一责任原则的替代方案?



我认为,如果我的类完成SRP,则不需要提取多个接口。 / p>

所以ISP看起来像解决方案,以防我们因为某些原因打破SRP。



我是对的? / p>

解决方案

否。举个例子,他们的责任是持续的数据例如。硬盘将类拆分为读写部分将不具有实际意义。但有些客户端只应该使用该类来读取数据,一些客户端只能写入数据,而有些客户端要做这两个。应用ISP在这里与三个不同的接口将是一个很好的解决方案。


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 ?

解决方案

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.

这篇关于界面隔离原则只是一个单一责任原则的替代品?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆