面向对象编程
Object-Oriented Programming
Objects and object-oriented programming are concepts that became popular in the early 1990s. Early computer languages, like C, did not have the concept of an object. However, it turned out that objects are an easy-to-understand paradigm for humans . Objects can be used to model many real-life concepts and situations. Most, if not all, new languages have the concept of objects these days. So what you’re about to learn will conceptually apply to other languages too: this is fundamental computer science.
对象=算法+数据结构
程序=(对象+对象+...)+消息
- 设计所需的各种类和对象,将数据与操作封装在一起
- 考虑如何向有关对象发送信息,调用函数实现功能
基本概念
对象 Object
构成系统的基本单位,由一组属性和一组行为构成
- 属性:attribute 静态特征
- 行为:behavior 动态特征
(有编程语言称为:方法 method)
接受外部输入的信息(消息 message)产生特定的功能
类
class
对象的类型,代表一批对象的共性和特征
- 类是对象的抽象、对象的模板
只是抽象的类型,不占用储存空间 - 对象是类的具体实例 (instance)
具体存在,占用储存空间
消息 message
对对象的控制,对函数的调用
基本思想
封装
继承
直接获得已有的性质和特征,而不必重复定义