面向对象编程

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.

对象=算法+数据结构
程序=(对象+对象+...)+消息

  1. 设计所需的各种类和对象,将数据与操作封装在一起
  2. 考虑如何向有关对象发送信息,调用函数实现功能

基本概念

对象 Object
构成系统的基本单位,由一组属性和一组行为构成

class
对象的类型,代表一批对象的共性和特征

消息 message
对象的控制,对函数的调用

基本思想

封装

继承

直接获得已有的性质和特征,而不必重复定义

多态

重载