本文介紹S.O.L.I.D原則中的介面隔離原則(Interface Segregation Principle,縮寫為ISP)。
該原則主旨為與其建造一個龐大擁腫的介面(interface),不如改成為數個小型介面,方便開耦合和重構。
Too many is better than too few
舉個例子來說,你有[Animal]介面,動物會做
[吃],[動],[睡]

圖上IAnimal介面包含三個動作可作用於所有動物例如熊,虎,象等等。但如果有一個Plant(植物)類別要繼承此IAnimal介面,則IAnimal大部份的行為並不符合Plant,所以並不適用。
試想我們換成另外一個情境。我們將IAnimal拆成三個小型介面(eat, move, sleep)。植物(Plant)雖然不會[動]也不會[睡],但會消耗能源和排放氧氣,所以吃(eat)動作是可以作用於[Plant]植物類別上的。

此例子顯示輕小型的介面比起巨型的介面(interface)更具有擴充性和可用性。反觀如果[Plant]繼承了IAnimal介面需要實作太多沒有必要的方法,且會需要修改很多的程式碼。