界面隔离原则只是一个单一责任原则的替代品? [英] Is Interface segregation principle only a substitue for Single responsibility principle?
问题描述
我认为,如果我的类完成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屋!