接口隔离原则 - 编程到接口 [英] Interface Segregation Principle- Program to an interface

查看:25
本文介绍了接口隔离原则 - 编程到接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读有关 SOLID 和其他设计原则的文章.我认为 ISP 与编程接口,而不是实现"相同.但看起来这些是不同的原则?

I was reading about SOLID and other design principles. I thought ISP was the same as "Program to an interface, not an implementation". But it looks like these are different principles?

有区别吗?

推荐答案

ISP 专注于每个接口代表一种离散和内聚行为的想法.

ISP is focused on the idea of each interface representing one discrete and cohesive behavior.

也就是说,一个对象应该做的每个逻辑组的事情都会映射到一个特定的接口.一个类可能想要做几件事,但每件事都会映射到代表该行为的特定接口.这个想法是每个界面都非常专注.

That is, each logical group of things an object should do would map to a single specific interface. A class might want to do several things, but each thing would map to a specific interface representing that behavior. The idea is each interface is very focused.

这篇关于接口隔离原则 - 编程到接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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