Essential OOP
今天無情無義地拋開 IS term project,向同學講述超濃縮的 OOP 核心概念。從 data abstraction 一路講到 polymorphism,可以感覺已經連成一氣了。(但我不知道有沒有表達出來 XD。)以下是我擬的大綱(防止偏離主幹),DBC 的 precodition / postcondition 實際講時跳過沒提。
1. data abstraction
object-oriented paradigm ==> object-oriented decomposition
What is an "object"? ==> behavior, responding to certain "messages"
send an object a message ==> invoke that object's instance method
oms., public instance method
interface: the general idea
abstraction (Andrew Koenig: "Abstraction is selective ignorance.")
==> data abstraction, procedure abstraction
interface (public members) vs. implementation (private members)
encapsulation ==> why? enforcing abstraction, state maintenance
Design by Contract (DBC): class invariants
state constructing ==> constructor
state destructing ==> garbage collector & explicit resourse release
(vs. destructor)
Doug McIlroy: "Those types are not 'abstract', they are as real as int and float."
2. class extension (inheritance) & polymorphism
perspective 1: program by difference
a subclass object = a superclass subobject + the subclass part
==> a subclass constructor must invoke one of its superclass constructors
Why member hiding?
essentially an extension of data abstraction
perspective 2: program to the interface
inheritance <==> IsA relationship between subclass and superclass
oms., a substitutable relationship (LSP)
reference type vs. actual type
Why method overriding? the message model
DBC: precoditions and postconditions of instance methods
==> access level raising, exception throws list, covariant return type
polymorphism: the interface perspective & the object perspective
2.1 abstract classes and interfaces
the superclass is just an abstract concept ==> no instantiation
abstract classes are always used in class extension
utility class ==> use a private constructor
Java class = implementation
Java interface ==> pure interface, no implementation
multiple implementation of interfaces
==> the object has many forms, i.e., the object perspective of polymorphism
JavaPL4e, p.131: "Any major class you expect to be extended, whether
abstract or not, should be an implementation of an interface."
==> program to the interface, not to the implementation (class)
看似份量不多,但也講了五、六個小時。感覺不錯 :)。
--
晚上要和 RMI、HTML、cookies 混戰了 XD。


<< 回到主頁