Object-oriented programming
| English | Chinese | Pinyin |
|---|---|---|
| object | 对象 | duì xiàng |
| instance | 实例 | shí lì |
| class | 类 | lèi |
| constructor | 构造函数 | gòu zào hán shù |
| inheritance | 继承 | jì chéng |
| subclass | 子类 | zi lèi |
| encapsulation | 封装 | fēng zhuāng |
| superclass | 父类 | fù lèi |
| polymorphism | 多态 | duō tài |
| abstraction | 抽象 | chōu xiàng |
Modelling the world as objects 对象
- OOP builds programs from objects — units that combine data and operations.
- Objects are instances 实例 of classes 类, and a few core ideas (the "four pillars") organise everything.
- It suits large systems, GUIs, simulations and games.
Programming concept lab
Connect examples to the programming idea they show.
Objects and classes
- An object combines attributes (data) and methods (operations).
- A class is the blueprint; an object is an instance of it.
- A constructor 构造函数 is a special method run when an object is created, to set up its attributes.

A class diagram lists a class's private attributes and its public methods

Inheritance 继承: partTime and fullTime are subclasses 子类 of employee
An object combines:
An object bundles its data (attributes) with the operations (methods) that act on it.
A constructor is a special method that:
The constructor initialises a new object's attributes at creation time.
The four pillars
- Encapsulation 封装 — an object's data is hidden behind its methods; outside code uses the public methods, not the data directly (so internals can change safely).
- Inheritance — a subclass specialises a superclass 父类, inheriting its members and adding/overriding them. Models "is-a" (a Manager is an Employee).
- Polymorphism 多态 — different objects respond to the same method call in their own way (every
ShapehasArea();CircleandRectangleeach implement it). - Abstraction 抽象 — show a simple interface, hide the implementation.

Four paradigms: low-level, imperative, object-oriented and declarative
Encapsulation means:
Encapsulation hides the data; outside code uses the public methods, so internals can change safely.
Inheritance models an "is-a" relationship (a Manager is an Employee), so a subclass inherits and extends its superclass.
Inheritance is "is-a" specialisation; "has-a" relationships are modelled by composition instead.
Polymorphism allows:
The same call (e.g. Area()) behaves correctly for each type — the caller need not know the exact class.
Match each OOP pillar to its meaning.
Encapsulation = hiding; inheritance = is-a specialisation; polymorphism = same interface, varied behaviour.
Inheritance and polymorphism
- Inheritance lets a class reuse and extend another class's features.
- Polymorphism lets the same method name behave differently for different classes.

Polymorphism: the same Area() call gives each shape its own result
You've got it
- an object = attributes (data) + methods (operations); a class is its blueprint
- a constructor runs at creation to set up the object
- four pillars: encapsulation (hide data), inheritance (is-a, subclass), polymorphism (same call, different behaviour), abstraction (simple interface)