← 返回资讯屏轩教育 · 行业资讯

Object-Oriented Programming for Edexcel A-Level | 面向对象编程(Edexcel A-Level)

2026-08-29 15:31 · 本文部分内容由AI辅助创作

📚 Object-Oriented Programming for Edexcel A-Level | 面向对象编程(Edexcel A-Level)

Object-oriented programming (OOP) is a programming paradigm that models real-world entities as objects containing both data (attributes) and behaviour (methods). It is a core part of the Edexcel A-Level Computer Science specification, appearing in theory questions and in the practical NEA project.

面向对象编程(OOP)是一种将现实世界实体建模为包含数据(属性)和行为(方法)的对象的编程范式。它是 Edexcel A-Level 计算机科学大纲的核心内容,出现在理论题和实践 NEA 项目中。


1. Classes and Objects | 类与对象

A class is a blueprint or template that defines the attributes (data) and methods (behaviour) of a type of object. An object is a specific instance of a class created at runtime. For example, the class Student may define attributes such as name, age, and grade; each Student object represents one actual learner with its own values.

类是定义某类对象的属性(数据)和方法(行为)的蓝图或模板。对象是在运行时创建的类的具体实例。例如,Student 类可以定义 name、age 和 grade 等属性;每个 Student 对象代表一名具有各自属性值的真实学生。

In Edexcel exam questions, you often need to identify a suitable class name, list its attributes, and write methods that operate on those attributes. Clear separation between class and object shows understanding of instantiation.

在 Edexcel 考试题中,经常需要确定合适的类名、列出其属性,并编写操作这些属性的方法。区分类与对象能体现对实例化过程的理解。


2. Attributes and Methods | 属性与方法

Attributes are the data fields stored inside an object, such as an integer age, a string name, or a boolean enrolled. Methods are the operations that define behaviour, such as calculateAverageMark() or updateAttendance(). Methods often read or modify attributes, so they should be designed to keep the object in a valid state.

属性是存储在对象内部的数据字段,例如整型 age、字符串 name 或布尔型 enrolled。方法是定义行为的操作,如 calculateAverageMark() 或 updateAttendance()。方法通常会读取或修改属性,因此应设计成使对象始终处于有效状态。

When modelling a problem, start by listing the nouns as candidate classes and the verbs as candidate methods. This simple technique aligns with Edexcel mark schemes that reward a clear mapping from problem statement to design.

建模问题时,可以把名词列为候选类,把动词列为候选方法。这种简单技巧符合 Edexcel 评分标准,能给清晰映射问题描述到设计的过程加分。


3. Constructors and Instantiation | 构造函数与实例化

A constructor is a special method that runs when an object is created. It usually initialises attributes to avoid undefined values. In pseudocode, a constructor often has the same name as the class and no return type. A default constructor takes no arguments, while a parameterised constructor accepts initial values.

构造函数是创建对象时运行的特殊方法,通常用来初始化属性以避免未定义的值。在伪代码中,构造函数通常与类同名,且没有返回类型。默认构造函数不带参数,而参数化构造函数接受初始值。

For example, a parameterised constructor for Student might accept newName, newAge, and newGrade, then assign them to attributes. In the exam, you must show correct assignment and not confuse the parameter name with the attribute name.

例如,Student 的参数化构造函数可以接受 newName、newAge 和 newGrade,再把它们赋给属性。考试中必须正确写出赋值过程,不能混淆参数名与属性名。


4. Encapsulation and Access Modifiers | 封装与访问修饰符

Encapsulation means hiding the internal state of an object and only exposing a controlled interface. Attributes are usually declared private so they cannot be changed directly from outside. Public getter and setter methods allow controlled access and validation.

封装意味着隐藏对象的内部状态,只暴露受控的接口。属性通常声明为 private,这样外部不能直接修改。公共的 getter 和 setter 方法可以提供受控访问和验证。

ModifierSame classSubclassOutside class
privateYesNoNo
protectedYesYesNo
publicYesYesYes

The table summarises typical access levels. Edexcel questions may ask you to choose the most appropriate modifier for a given attribute, rewarding answers that justify data protection.

上表总结了典型的访问级别。Edexcel 题目可能会要求为给定属性选择最合适的修饰符,能说明数据保护理由的答案会被加分。


广告 / Sponsored

5. Inheritance | 继承

Inheritance allows a subclass to derive attributes and methods from a superclass, supporting code reuse and an 'is-a' relationship. For example, Dog and Cat can inherit from Animal because a dog is an animal. The subclass may add its own specialised methods or override inherited ones.

继承允许子类从父类派生属性和方法,支持代码复用和“is-a”关系。例如,Dog 和 Cat 可以继承自 Animal,因为狗是动物。子类可以添加自己的专用方法或重写继承的方法。

In Edexcel pseudocode, you might write class Dog inherits Animal. The exam may ask you to state one advantage of inheritance, such as avoiding duplicate code, and one disadvantage, such as increased coupling between classes.

在 Edexcel 伪代码中,可能会写成 class Dog inherits Animal。考试可能会要求说明继承的一个优点(如避免重复代码)和一个缺点(如增加类之间的耦合)。


6. Polymorphism | 多态

Polymorphism means 'many forms' and allows the same method call to behave differently depending on the object's runtime type. This is typically achieved through method overriding, where a subclass provides its own implementation of a method defined in the superclass.

多态意为“多种形态”,允许同一个方法调用根据对象的运行时类型表现不同行为。这通常通过方法重写实现,即子类为父类中定义的方法提供自己的实现。

For instance, an array of Animal objects may contain Dog, Cat, and Bird instances. Calling the makeSound() method on each element invokes the appropriate subclass version, demonstrating dynamic dispatch. Edexcel questions often ask you to identify polymorphic behaviour from a scenario.

例如,一个 Animal 对象数组可以包含 Dog、Cat 和 Bird 实例。对每个元素调用 makeSound() 方法会触发相应子类的版本,体现动态分派。Edexcel 题目常要求从场景中识别多态行为。


7. Association, Aggregation and Composition | 关联、聚合与组合

Association is a general 'has-a' relationship between objects, such as a Student having a Tutor. Aggregation is a weaker whole-part relationship where the part can exist independently, such as a Department having Lecturers; if the Department closes, lecturers still exist. Composition is a stronger relationship where the part cannot exist without the whole, such as a House having Rooms; if the house is destroyed, rooms are too.

关联是对象之间一般的“has-a”关系,例如 Student 有 Tutor。聚合是一种较弱的整体-部分关系,其中部分可以独立存在,例如 Department 有 Lecturer;如果系关闭,讲师仍然存在。组合是一种更强的关系,部分不能脱离整体存在,例如 House 有 Room;如果房子被毁,房间也不复存在。

In UML, a hollow diamond represents aggregation and a filled diamond represents composition. Being able to distinguish these helps you design accurate class diagrams in Edexcel papers and NEA documentation.

在 UML 中,空心菱形表示聚合,实心菱形表示组合。能区分这些关系有助于在 Edexcel 试卷和 NEA 文档中设计准确的类图。


8. Abstract Classes and Interfaces | 抽象类与接口

An abstract class is designed to be a base class that cannot be instantiated directly. It may contain abstract methods (signatures without implementation) and concrete methods. An interface defines a contract of method

Published by TutorHao | A-Level 编程 Revision Series | aleveler.com

广告 / Sponsored
原版培生爱德思考试教材 统计数学2 Edexcel International A Level Mathematics…
数学 备考教辅 · 正版现货 · 学习备考通用
查看详情 / View on Taobao参考价 ¥198.0
广告 / Sponsored
英文原版 Edexcel International GCSE Maths Student Book 爱德思英国高中数…
数学 备考教辅 · 正版现货 · 学习备考通用
查看详情 / View on Taobao参考价 ¥170.9

更多咨询请联系16621398022(同微信)

备考资讯每日更新,关注不错过
考纲变化 · 科目分析 · 学习方法
扫码关注公众号 tutorhao
在微信里长按二维码识别关注
或截图后用「扫一扫 → 相册」选择本图
公众号:tutorhao