Icesleep

標題: Their modification and optimization [打印本頁]

作者: parvej64    時間: 2023-10-14 12:34
標題: Their modification and optimization
In this example, these would be the three categories Cars, Ships, and Aircraft: At first glance, you can see how much of a problem the construction of this interface poses, since it requires the implementation of the , and methods. As we all know a car can only drive so in and method it throws exception with appropriate message, class works the same way as boat can swim and exception must be thrown for other methods too. For airplanes, both methods are reasonable since airplanes can fly both on landing gear and in the air, but for the method, the exception must be thrown.
  
Such code violates the interface segregation principle because interfaces are not specialized and force implementation of methods that not all classes require. This interface is too generic and contains too many implementation possibilities. So how do we change photo retouching the code so that it meets the interface isolation principle while allowing cars to drive, ships to swim, and planes to drive and fly? Each of these activities should be separated into a separate interface so that an implementation can choose which interface it implements based on the required activity. So, let's create three appropriate interfaces.



Interfaces designed in this way are specialized and have terms by which we can determine what exactly they are responsible for. We have organized the interfaces correctly and now it is enough for each vehicle to implement only the functionality it really needs. So let's look at the improved implementation of the , and classes: Thanks to the interface isolation principle, our code becomes shorter and simpler. Types are interchangeable, even when a base type is used, its derived type can be used without changing the behavior of the first type. This issue will become clearer after an example.








歡迎光臨 Icesleep (http://icesleep.s-n.tw/) Powered by Discuz! X3.3
一粒米 | 中興米 | 論壇美工 | 設計 抗ddos | 天堂私服 | ddos | ddos | 防ddos | 防禦ddos | 防ddos主機 | 天堂美工 | 設計 防ddos主機 | 抗ddos主機 | 抗ddos | 抗ddos主機 | 抗攻擊論壇 | 天堂自動贊助 | 免費論壇 | 天堂私服 | 天堂123 | 台南清潔 | 天堂 | 天堂私服 | 免費論壇申請 | 抗ddos | 虛擬主機 | 實體主機 | vps | 網域註冊 | 抗攻擊遊戲主機 | ddos |