Object-Based Programming usually refers to objects without inheritance
[Cardelli 85] and hence without polymorphism, as in '83 Ada and Modula-2.
These languages support abstract data types (Adts) and not classes, which
provide inheritance and polymorphism.
(注意 沒有 inheritance 就沒有 polymorphism!!!)
Ada95 and Modula-3; however, support both inheritance and
polymorphism and are object-oriented.
Inheritance means that you can say, in the initial class declaration, that a class is derived from a more generic class.
Inheritance 就是要 Compiler 幫忙 copy !(by tsaiwn@csie.nctu.edu.tw) Inheritance(繼承), 就是擴充 (extends; Java 就是這樣用), 是指Sub Class(子類別)繼承Super Class(父類別)的資料欄位與函數(data and methods) (注意少數 functions 如 constructor 與 destructor 沒有繼承過來!) 例如, 已經設計一個 class 叫作鬧鐘, 現在要設計一個豪華鬧鐘, 顯然不該從零開始, 只要把鬧鐘拿來加以" 擴充即可! 所以 Java: class 鬧鐘 { ... } class 豪華鬧鐘 extends 鬧鐘 { // 都不寫就與 鬧鐘 一樣... } |
Polymorphism: (多型)(by tsaiwn@csie.nctu.edu.tw)
用基礎類別(base class)的指標 (C++)或參考(Reference, in Java) 去操作衍生類別 (derived class)的物件; 例如: class Animal { //... public void cry( ) { ... } } class Dog { public void cry( ) { ... } } class Cat { public void cry( ) { ... } } void test( ) { Animal a = null; a = new Dog( ); a.cry( ); // who is crying? a = new Cat( ); a.cry( ); // who is crying? } |
[Cardelli 85, p481] state "that a language is Object-Oriented if and only if it satisfies the following requirements:
|
Object Based programming does not provide the important 2 features of Object Oriented language: inheritance and polymorphism. Object Based language use pre-defined objects and example are Visual Basic(version 6 and earlier). Please be aware that VB.net supports inheritance and polymorphism and thus it is a true Object Oriented Programming language.
Polymorphism is a programming language feature that allows values of different data types to be handled using a uniform interface. And thus Polymorphism requires the technique of so called dynamic binding or late binding.
Please note that "Polymorphism" is totally different from "Overloading"
(Method Overloading, funtion name overloading).
Where Overloading uses the static binding to bind the function name to
it's function body according to the function prototype.
ADT : Abstract Data Type 抽象資料型別:
把資料以及與資料有關的 functions 封裝(Encapsulate)在一個
程式單元(program unit)如 C++ 的 class 內,
以便可以當作一種獨立的 Object Type 使用, 此即 ADT.
一般的建議是 data 儘量藏起來 (hide, private),
functions 儘量公開 (public). (by tsaiwn@csie.nctu.edu.tw)
U are the
-th visitors to this page.
回到作業目錄
回到課程目錄