「Java」「interface欄位與方法」 Chapter5 Question4

問題:
which two forms of abstraction can a programmer use in java?
哪兩種抽象形式能在 Java程式中使用??

選擇:
  1. enums 列舉
  2. primitives 基本資料型別
  3. abstract classes 抽象類別
  4. concrete classes 實體類別
  5. primitive wrappers 外包類別
  6. interfaces 介面

Answer:
3 , 6

提要:
  • Abstract classes:父類別在設計的時候,其主要目的若是要讓其他類別繼承,則我們通常稱這樣的祖先類別為abstract classes。關於這一點雖然課本上這樣解釋,但是實務上我們會說一個無法產生instance的class就稱之為abstract class。 
  • Concrete class:和abstract classes相反,一個類別其設計之主要目的就是要讓人產生instance,則稱此類別為concrete class。實務上只要是能產生instance的類別都稱之為concrete classes。   
     
    Interfaces:  
     
    Clients remain unaware of the specific types of objects they use, as long as the objects adhere to the interface that clients expect. 
     
    Clients remain unaware of the classes that implement these objects. Clients only know about the abstract class(es) defining the interface.
     
    This so greatly reduces implementation dependencies between subsystems that it leads to the following principle of reusable object-oriented design:

    Program to an interface, not an implementation.

    Don't declare variables to be instances of particular concrete classes. Instead, commit only to an interface defined by an abstract class.

留言

這個網誌中的熱門文章

[Excel]國曆轉農曆VBA

「CSS」「div區塊介紹」 三欄式網頁排版設計

「生活」眉毛觀人