本文介绍了在SOLID中,SRP和ISP有什么区别? (单一责任原则和接口隔离原则)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SOLID 接口隔离原理"与单个"有何不同?责任原则"?

How does the SOLID "Interface Segregation Principle" differ from "Single Responsibility Principle"?

维基百科有关SOLID的条目

但是,对我来说,这听起来像只是将SRP应用于接口和类.毕竟,如果一个接口仅负责一项概念上的事情,那么您将无法进一步细分它.

However, to me that sounds like just applying the SRP to interfaces as well as classes. After all, if an interface is only responsible for just one conceptual thing, than you wouldn't be able to break it down further.

我是否丢失了某些内容,或者ISP在SRP方面有点多余?如果不是,那么ISP暗示SRP没有什么意思?

Am I missing something, or is ISP sort of redundant with SRP? If not, then what does ISP imply that SRP does not?

推荐答案

SRP告诉我们,在模块中您仅应承担单一责任.

SRP tells us that you should only have a single responsibility in a module.

ISP告诉我们,不应强迫您面对超出实际需要的范围.如果要从接口I使用print()方法,则不必为此实例化SwimmingPoolDriveThru类.

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.

更具体地说,直截了当地,他们对同一个想法有不同的看法-SRP更侧重于设计者方的观点,而ISP更侧重于客户端方的观点,观点.所以你基本上是对的.

More concretely, and going straight to the point, they are different views on the same idea -- SRP is more focused on the designer-side point-of-view, while ISP is more focused on the client-side point-of-view. So you're basically right.

全部来自

如此

@ http://en.wikipedia.org/wiki/Interface_segregation_principle#Origin

这篇关于在SOLID中,SRP和ISP有什么区别? (单一责任原则和接口隔离原则)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-18 05:35