接口隔离原则

接口隔离原则(英語:interface-segregation principles, 缩写:ISP)指明客户(client)不應被迫使用對其而言無用的方法或功能。[1]接口隔离原则(ISP)拆分非常庞大臃肿的接口成为更小的和更具体的接口,这样客户将会只需要知道他们感兴趣的方法。这种缩小的接口也被称为角色接口(role interfaces)。[2]接口隔离原则(ISP)的目的是系统解开耦合,从而容易重构,更改和重新部署。接口隔离原则是在SOLID中五个面向对象设计(OOD)的原则之一,类似于在GRASP中的高内聚性[3]

在面向对象设计中的重要性 编辑

面向对象设计中,接口(interface)提供了便于代码在概念上解释的抽象层,并建立了避免依赖的一个屏障。

参看 编辑

参考文献 编辑

  1. ^ Martin, Robert (2002). Agile Software Development: Principles, Patterns and Practices. Pearson Education.
  2. ^ Role Interface. [2014-02-22]. (原始内容存档于2021-10-09). 
  3. ^ David Hayden, Interface-Segregation Principle (ISP) - Principles of Object-Oriented Class Design. [2014-02-22]. (原始内容存档于2010-08-20). 

外部链接 编辑