- Design Patterns and Best Practices in Java
- Kamalmeet Singh Adrian Ianculescu LUCIAN PAUL TORJE
- 210字
- 2021-06-25 20:52:30
Interface Segregation Principle
The following quote is taken from https://www.oodesign.com/interface-segregation-principle.html link:
"Clients should not be forced to depend upon interfaces that they don't use."
When applied, the Interface Segregation Principle (ISP) reduces the code coupling, making the software more robust, and easier to maintain and extend. ISP was first announced by Robert Martin, when he realized that if the principle is broken and clients are forced to depend on interfaces they don't use, the code becomes so tightly coupled that it's almost impossible to add new functionality to it.
In order to better understand this, let's again take the car-service example (refer to the following diagram). Now we need to implement a class named Mechanic. The mechanic repairs cars, so we add a method of repair car. In this case, the Mechanic class depends upon the I class. However, the Car class exposes a richer sets of methods than the Mechanic class needs:

This is a bad design because if we want to replace a car with another one, we need to make changes in the Mechanic class, which violates the open/closed principle. Instead, we must create an interface that exposes only the relevant methods required in the Mechanic class, as shown in the following diagram:

- LabVIEW2018中文版 虛擬儀器程序設(shè)計(jì)自學(xué)手冊
- C語言程序設(shè)計(jì)(第2 版)
- Responsive Web Design with HTML5 and CSS3
- Data Analysis with IBM SPSS Statistics
- HTML5+CSS3+JavaScript Web開發(fā)案例教程(在線實(shí)訓(xùn)版)
- 深入淺出RxJS
- Getting Started with Python Data Analysis
- Python面向?qū)ο缶幊蹋簶?gòu)建游戲和GUI
- WebRTC技術(shù)詳解:從0到1構(gòu)建多人視頻會議系統(tǒng)
- 程序設(shè)計(jì)基礎(chǔ)教程:C語言
- 21天學(xué)通C++(第5版)
- Getting Started with Web Components
- H5頁面設(shè)計(jì)與制作(全彩慕課版·第2版)
- 深入實(shí)踐C++模板編程
- Game Development Patterns and Best Practices