物件導向 Object-Oriented Programming
名詞解說
Object 物件
An object is characterized by a number of operations and a state which remembers the effect of these operations.(p.44) - from 《Object-Oriented Software Engineering》
物件特徵是擁有大量的動作(operations)和狀態(state),並可記憶各種動作(operations)的影響
Class
A class represents a template for several objects and describes how these objects are structured internally. Objects of the same class have the same definition both for their operations and for their information structures.(p.50) - from 《Object-Oriented Software Engineering》
- class代表一個模版。有勇一些Objects和描述這些Objects如何建構。
- 同一個class的Ojbect在其的操作(operations)與結構上有相同的定義
- Class是用來定義object的一種東西,class的內容包含了動作(operations)與資料(data)。
Instance 實例
An instanceis an object created from a class. The class describes the (behavior and information)structure of the instance, while the current state of the instance is defined by the operations performed on the instance.(p.50) - from 《Object-Oriented Software Engineering》
- Instance是實現class的Object
- 在Instance上,class描述行為與資訊的結構。在Instance當前的狀態定義了操作Instance的表現
- 一個object就是某個class的instance,換句話說可以把object和instance看作是同樣的東西。只是在某些場合大家比較習慣用object這個說法,其他場合則是會用instance。
operations 動作
- 動作(operations)、方法(methods)和行為(behaviors)可以看作同義詞。
- 理想上一個object的狀態只能透過動作去改變它
attributes 屬性
- 資料成員(data members)和屬性(attributes)是同義詞,都是用來儲存物件的狀態。