B3 Object oriented programming
For the new IB Diploma Computer Science syllabus to start teaching in August 2025, and for first examinations in May 2027.
Unit and lesson overviews will be gradually published as developed.
- Lesson 1: Introducing OOP
- Lesson 2: Designing classes
- Lesson 3: Instantiating objects
- Lesson 4: Encapsulation
- Lesson 5: Statics & non-statics
- Lesson 6,7,8: Programming scenarios
- Lesson 9: Inheritance (HL)
- Lesson 10: Polymorphism (overriding) (HL)
- Lesson 11: Abstract classes (HL)
- Lesson 12: Composition & aggregation (HL)
- Lesson 13: Design patterns (HL)
- Lesson 14,15,16,17: Programming scenarios (HL)
- Lesson 18,19: Exam style questions
- Lesson 20: Assessment
Lesson 1: Introducing OOP
B3.1.1 Evaluate the fundamentals of OOP.
Lesson 2: Designing classes
B3.1.2 Construct a design of classes, their methods and behaviour.
Lesson 3: Instantiating objects
B3.1.4 Construct code to define classes and instantiate objects.
Lesson 4: Encapsulation
B3.1.5 Explain and apply the concepts of encapsulation and information hiding in OOP.
Lesson 5: Statics & non-statics
B3.1.3 Distinguish between static and non-static variables and methods.
Lesson 6,7,8: Programming scenarios
Exercise 1: Student and Course Enrollment System
Focus Classes: Student, Course
- Draw a UML class diagram for the Student class, including attributes for name, student ID, and year level.
- Implement the Python constructor
__init__()
based on the UML diagram. - Make the student ID (
student_id
) a private attribute (using a double underscore). - Implement a public method
get_student_id()
to allow controlled, read-only access to the private ID. - Introduce a static attribute called
__student_count
(initialized to 0) to the class. This attribute should be incremented inside the constructor every time a new student object is instantiated. - Add a static method called
get_total_students()
that returns the value of the__student_count
. - Implement the Course class with attributes like
course_code
,name
,current_enrollment
, andmax_capacity
. - Add a non-static method
is_full(self)
that returns True if the course’s current enrollment is equal to the max capacity, and False otherwise.
Exercise 2: Library Item Management
Focus Class: LibraryItem
- Define
LibraryItem
with attributes fortitle
,itemID
, and a loan status attribute,__is_on_loan
, which should be initialized to False in the constructor and kept private. - Implement a public non-static method
borrow_item()
that sets__is_on_loan
to True, but only if the item is currently available. It should print a message indicating success or failure. - Implement a corresponding public non-static method
return_item()
that sets the status back to False. - Add a non-static method
display_status()
that prints the item’s title and its current loan status (e.g., “Available” or “On Loan”). This uses the internal state but presents it publicly. - Draw the complete UML class diagram for the
LibraryItem
class. Use correct notation for private and public attributes/methods. - Add a static attribute and corresponding static method to track and report the total number of
LibraryItem
objects ever created (the library’s total inventory size).
Exercise 3: Point or Vector (Mathematical/Geometric)
Focus Class: Point2D
- Create the
Point2D
class with private attributes__x
and__y
, which are initialized via the constructor. - Implement public getter methods (
get_x()
,get_y()
) and public setter methods (set_x(new_x)
,set_y(new_y)
) for the coordinates. This teaches the difference between direct attribute access and controlled method access. - Implement a non-static method
distance_from_origin(self)
that calculates and returns the distance of this specific point from the origin(0, 0)
. - Implement a static method
create_origin()
that returns a new Point2D object initialized at(0,0)
.
Lesson 9: Inheritance (HL)
B3.2.1 Explain and apply the concept of inheritance in OOP to promote code reusability.
Lesson 10: Polymorphism (overriding) (HL)
B3.2.2 Construct code to model polymorphism and its various forms, such as method overriding.
Lesson 11: Abstract classes (HL)
B3.2.3 Explain the concept of abstraction in OOP.
Lesson 12: Composition & aggregation (HL)
B3.2.4 Explain the role of composition and aggregation in class relationships.
Lesson 13: Design patterns (HL)
B3.2.5 Explain commonly used design patterns in OOP.