1、what is object-orientation?
The term object-oriented (OO) means that we organize software as a collection of discrete objects that incorporate both data structure and behavior.
object 对象
Something perceptible by one or more of the senses, especially by vision or touch.combines both data structure and behavior.
Object-orientation include four aspects:
- identity 标识符
- classification 分类
- inheritance 继承
- polymorphism 多态
identity 标识
the data is quantized into discrete, distinguishable entities called boject.标识是数据被量化成对象的离散的可辨识的实体
Two objects are distinct even if all their attribute values are
identical. Such object references are uniform and independent of the
contents of the objects
classification 分类
objects with the same data structure or attributes(属性) and behavior or operations(操作) are grouped into a class.
Classification means that objects with the same data structure (attributes) and behavior (operations) are grouped into a class.
inheritance 继承
inheritance is the sharing of attributes and operations among classes based ono a hierarchical(分层) relationship.
A superclass(父类) has general information that subclasses(子类) refine and elaborate.
Inheritance is the sharing of attributes and operations among classes based on a hierarchical relationship.
polymorphism 多态
the same operation may behave differently for different classes.一个相同的操作会有不同的行为
Polymorphism means that the same operation may behave differently for different classes.
operation 操作
An operation is a procedure or transformation that an object performs or is subject to.操作是对象执行或被执行的一个过程或转换
class 类
class is an abstraction(抽象) that describes properties(属性) and ignores the rest
instance 实例
each object is said to be an instance of its class.
message 消息
The communication structure between objects is message.
method 方法
The behavior’s implement process is method.
2、Elements of object-orientation
abstraction 抽象
Abstraction lets you focus on essential aspects of an application while ignoring details.
抽象是指强调事物的本质、内在的属性,而忽略一些无关紧要的属性。在决定如何用代码实现一个对象之前,先确定对象的本质意义和行为。使用抽象可以尽可能避免过早考虑一些细节,但是抽象是有限度的,要合理抽象。
Encapsulation 封装性
Encapsulation (also information hading) separates the external aspects of an object, that are accessible to other objects, from the internal implementation details, that are hidden from other objects.
封装性是指将对象的外部因素(即可以被其他对象访问的部分)与内部实现细节(即其他对象不可见的部分)分离开来。这种内部实现与外部可访问性的分离是保证软件具有良好的模块性的基础。
Encapsulation prevents portions of a program from becoming so interdependent that a small change has massive ripple effects.
封装防止了程序相互依赖性而带来的变动影响。
Combing Data and Behavior 数据和行为的结合
The caller of an operation need not consider how many implementations exist. Operator polymorphism shifts the burden of deciding what implementation to use from the calling code to the class hierarchy.
sharing 共享性
OO techniques promote sharing at different levels.
Inheritance of both data structure and behavior let subclass share
common code.
- Sharing in same class
同一个类中的对象有着相同的数据结构和相同的行为特征。 - Sharing in same application
在同一应用的类层次结构中,存在继承关系的各相似子类中,存在数据结构和行为的继承,使各相似子类共享相同的结构和行为。 - Sharing in different application
通过类库这种机制和结构来实现不同应用中的信息共享。
Emphasis on the Essence of an Object 强调对象结构而不是程序结构
OO technology stresses what an object is, rather than how it is used. The uses of an object depend on the details of the application and often change during development.
面向对象技术强调明确对象是什么,而不强调对象是如何被使用的。对象的使用依赖于应用时的细节,并且它的使用在整个开发过程中可能不断变化。
Synergy 协同
Identity, classification, polymorphism, and inheritance characterize OO languages. Each of these concepts can be used in isolation, but together they complement each other synergistically.
对象唯一性,分类性,多态性和继承性都是OO语言的特性。这些概念中的每一个都可以分开使用,但是结合在一起,它们就会相互促进,互相补充。
3、three model of object-orientation
class model 类模型
类模型表示了静态的、结构化的系统数据性质,描述了系统的静态结构,是从客观世界实体的对象关系角度来描述。表现了对象间的相互关系。该模型重点关心系统中对象的结构、属性和操作。类模型使用了类图(class diagram)工具来刻画,是其他两个模型的框架。
state model 状态模型
状态模型是与时间和变化有关的系统性质。该模型描述了系统的控制结构,表示了瞬时的、行为化的系统控制性质;它关心的是系统的控制,操作的执行顺序;它从对象的时间和状态的角度出发,表现了对象的相互行为。状态模型使用状态图(state diagram)来确定并实现这种控制。
interaction model 交互模型
交互模型描述了系统中的对象如何协作以完成所有的任务。也就是说,交互模型表明一个计算如何从输入值得到输出值。交互模型使用用例图(user case),序列图(sequence diagram),活动图(activity diagram)等。
交互模型指出了发生了什么,状态模型确定了什么时候发生,类模型确定发生的客体。