📚 Object-Oriented Programming Exam Guide for IB & CCEA | IB 与 CCEA 计算机:面向对象考点精讲
Object-oriented programming (OOP) is a fundamental paradigm in computer science, forming the backbone of modern software development. For students taking IB Computer Science (both SL and HL) and CCEA A-Level or GCSE specifications, mastering OOP concepts is essential to succeed in theoretical papers, practical programming tasks, and design assessments.
面向对象编程(OOP)是计算机科学中的基本范型,也是现代软件开发的基石。对于学习 IB 计算机科学(SL 和 HL)以及 CCEA A-Level 或 GCSE 课程的学生来说,掌握面向对象的核心概念对应对理论考试、实际编程任务和设计评估至关重要。
1. What is Object-Oriented Programming? | 什么是面向对象编程?
OOP is a programming model organised around 'objects' rather than 'actions'. Unlike procedural programming, which focuses on writing functions or procedures, OOP combines data (attributes) and behaviour (methods) into objects. This approach makes programs easier to understand, maintain, and extend.
面向对象编程是一种围绕“对象”而非“动作”组织的编程模型。与注重编写函数或过程的面向过程编程不同,OOP 将数据(属性)和行为(方法)结合到对象中。这种方法使程序更易于理解、维护和扩展。
The four core principles of OOP are encapsulation, inheritance, polymorphism, and abstraction. Both IB and CCEA syllabi require students to explain these concepts and apply them in design and coding scenarios.
OOP 的四个核心原则是封装、继承、多态和抽象。IB 和 CCEA 教学大纲都要求学生解释这些概念,并在设计和编码场景中应用它们。
2. Classes and Objects | 类与对象
A class is a blueprint or template that defines the structure and behaviour of objects. It specifies the attributes (fields/properties) and methods (functions) that objects created from the class will possess.
类是定义对象结构和行为的蓝图或模板。它指定了由该类创建的对象将具备的属性(字段/特性)和方法(函数)。
An object is a concrete instance of a class. For example, if Car is a class, then myCar = new Car() creates an object myCar that can store specific data like colour and speed. In IB exams, you may be asked to instantiate objects and handle references.
对象是类的具体实例。例如,如果 Car 是一个类,那么 myCar = new Car() 就会创建一个对象 myCar,它可以存储颜色和速度等具体数据。在 IB 考试中,你可能会被要求实例化对象并处理引用。
3. Encapsulation and Data Hiding | 封装与数据隐藏
Encapsulation is the practice of bundling data (attributes) and methods that operate on that data within a single unit (class) and restricting direct access to some of the object's components. This is typically achieved using access modifiers (private, public, protected).
封装是将数据(属性)和操作这些数据的方法捆绑到一个单一单元(类)中,并限制对对象某些组件的直接访问的做法。这通常通过访问修饰符(private、public、protected)来实现。
Data hiding maintains integrity by preventing external code from accidentally modifying sensitive data. Instead, getter and setter methods provide controlled access. CCEA questions often ask candidates to complete class definitions with appropriate visibility and accessor methods.
数据隐藏通过防止外部代码意外修改敏感数据来维护完整性。相反,getter 和 setter 方法提供了受控的访问。CCEA 考题经常要求考生使用合适的可见性和访问方法完成类定义。
4. Inheritance and Code Reuse | 继承与代码复用
Inheritance allows a new class (subclass) to acquire properties and methods from an existing class (superclass). This promotes code reuse and establishes a hierarchical relationship. In Java, the extends keyword is used.
继承允许一个新类(子类)从现有类(超类)获取属性和方法。这促进了代码复用并建立了层次化关系。在 Java 中,使用 extends 关键字。
A subclass can override inherited methods to provide specialised behaviour. IB HL Paper 2 might involve designing a class hierarchy where a superclass Vehicle is extended by Car and Bicycle. CCEA also expects students to trace inheritance chains and predict output.
子类可以重写继承的方法以提供专门的行为。IB HL 试卷 2 可能涉及设计一个类层次结构,其中超类 Vehicle 被 Car 和 Bicycle 扩展。CCEA 也要求学生追踪继承链并预测输出。
5. Polymorphism: Method Overriding and Overloading | 多态:方法重写与重载
Polymorphism means 'many forms'. It allows objects of different classes to be treated as objects of a common superclass. The most common forms are method overriding (runtime polymorphism) and method overloading (compile-time polymorphism).
多态意味着“多种形态”。它允许将不同类的对象当作共同超类的对象来对待。最常见的形式是方法重写(运行时多态)和方法重载(编译时多态)。
Method overriding occurs when a subclass provides a specific implementation of a method already defined in its superclass. The method signature must be identical. Overloading, on the other hand, involves multiple methods with the same name but different parameter lists within the same class.
方法重写发生在子类为其超类中已定义的方法提供特定实现时。方法签名必须完全相同。另一方面,重载涉及在同一个类中有多个名称相同但参数列表不同的方法。
Both IB and CCEA exam questions often ask to distinguish between these two types of polymorphism and to give examples. A typical IB question might ask: 'Explain how a draw() method can be polymorphic in a shape hierarchy.'
IB 和 CCEA 考试题目经常要求区分这两种类型的多态并举例说明。一个典型的 IB 问题可能是:“解释 draw() 方法如何在形状层次结构中实现多态。”
6. Abstraction and Interfaces | 抽象与接口
Abstraction focuses on hiding complex implementation details and showing only the essential features of an object. Abstract classes and interfaces are key tools. An abstract class cannot be instantiated and may contain abstract methods (without a body).
抽象侧重于隐藏复杂的实现细节,只展示对象的必要特征。抽象类和接口是关键工具。抽象类无法实例化,可以包含抽象方法(没有方法体)。
An interface defines a contract of methods that implementing classes must fulfil. In IB Computer Science, interfaces appear in Option D (OOP) and HL paper. CCEA also covers interfaces as part of modern software design.
接口定义了实现类必须履行的方法契约。在 IB 计算机科学中,接口出现在选修 D(OOP)和 HL 试卷中。CCEA 也将接口作为现代软件设计的一部分来考查。
An example: interface Printable { void print(); } and a class Document implements Printable. This promotes loose coupling and flexibility.
例如:interface Printable { void print(); },然后类 Document 实现 Printable。这促进了松耦合与灵活性。
7. Constructors | 构造方法
A constructor is a special method invoked when an object is created. It initialises the object's state. In languages like Java, a constructor has the same name as the class and no return type. Default constructors are provided if none is explicitly defined.
构造方法是创建对象时调用的特殊方法,用于初始化对象的状态。在 Java 等语言中,构造方法与类同名且没有返回类型。如果没有显式定义构造方法,则会提供默认构造方法。
Parameterised constructors accept arguments to set initial values. Overloaded constructors allow multiple ways to instantiate an object. Exam questions may ask to write or analyse constructors, including the use of this keyword.
带参数的构造方法接受参数来设置初始值。重载的构造方法允许多种方式实例化对象。考试题目可能要求编写或分析构造方法,包括 this 关键字的使用。
8. Access Modifiers | 访问修饰符
Access modifiers control the visibility and accessibility of class members. The three primary modifiers in Java (and similar languages) are:
- public - accessible from any class.
- private - accessible only within the same class.
- protected - accessible within the same package and subclasses.
访问修饰符控制类成员的可见性和可访问性。Java(及类似语言)中的三种主要修饰符是:
- public(公有)- 可从任何类访问。
- private(私有)- 仅可在同一类中访问。
- protected(受保护)- 可在同一包和子类中访问。
If no modifier is used, it is known as package-private (default), which is often tested in IB and occasionally in CCEA. Candidates must apply appropriate modifiers to enforce encapsulation.
如果不使用修饰符,则称为包私有(默认),这在 IB 中经常考查,CCEA 偶尔也会考查。考生必须应用合适的修饰符来实现封装。
9. Static vs Instance Members | 静态成员与实例成员
Static members (variables and methods) belong to the class itself rather than to any specific object. They are accessed using the class name, e.g., Math.PI. Instance members, on the other hand, are tied to each object.
静态成员(变量和方法)属于类本身,而不是任何特定对象。它们通过类名访问,例如 Math.PI。而实例成员则与每个对象绑定。
Static methods often serve as utility functions and cannot access instance variables directly. In exam contexts, students might be asked to identify appropriate use of static and to correct errors where static methods improperly reference instance fields.
静态方法通常用作工具函数,不能直接访问实例变量。在考试中,学生可能会被要求识别 static 的适当用法,并纠正静态方法不当引用实例字段的错误。
10. UML Class Diagrams | UML 类图
Unified Modeling Language (UML) class diagrams are a standard way to visualise OOP designs. A class is represented as a rectangle divided into three sections: class name (top), attributes (middle), and methods (bottom). Visibility symbols (+ public, - private, # protected) are used.
统一建模语言(UML)类图是可视化 OOP 设计的标准方式。类表示为一个分成三部分的矩形:类名(顶部)、属性(中间)和方法(底部)。使用可见性符号(+ 公有, - 私有, # 受保护)。
Relationships like inheritance (solid line with hollow triangle), association, and dependency are drawn. IB HL Paper 2 typically includes a design question requiring a complete UML class diagram. CCEA also expects students to interpret and draw simple UML diagrams.
继承(带空心三角形的实线)、关联和依赖等关系会被绘制出来。IB HL 试卷 2 通常包含一个要求绘制完整 UML 类图的设计题。CCEA 也希望学生能解释和绘制简单的 UML 图。
Published by TutorHao | Computer Science Revision Series | aleveler.com
更多咨询请联系16621398022(同微信)

或截图后用「扫一扫 → 相册」选择本图