Fundamentals of Object-Oriented Programming
Evaluate the fundamentals of OOP
In this lesson
- Distinguishing classes from objects
- Describing encapsulation, inheritance and polymorphism with real-world examples
- Modelling real-world entities as classes with attributes and behaviours
- Evaluating the advantages and disadvantages of OOP for different programs
LearnFrom variables to objects
CodeParallel lists go wrong
Puffin eats Insects Toucan eats Fish
Each bird’s details are split across two lists linked only by position. Removing from one list and forgetting the other silently pairs every bird with the wrong diet.
CodeOne object per bird
Puffin eats Fish Toucan eats Fruit
Bird is a class. Each new Bird(…) / Bird(…) creates an object that keeps one bird’s name and diet together, so they can never be separated.
LearnClasses and objects
LabObjects in memory
Create Player objects from the Player class, call their methods and assign variables. Watch the variables on the left and the objects they refer to.
The Player class
Variables
p1 → not created
p2 → not created
p3 → not created
No objects yet: a class on its own is only a blueprint.
- Not done: Create two different Player objects
- Not done: Change one player’s score while another player keeps its own score
- Not done: Make two variables refer to the same object, then change it through one of them
LearnThree key ideas
CheckMatch the terms
Select a term on the left, then its description on the right.
CheckQuick check
A program has a Student class and creates 30 student objects. How many sets of student attribute values are stored?
LearnAdvantages and disadvantages of OOP
| Advantages | Disadvantages |
|---|---|
| Models real-world entities directly, so the design is easier to understand and discuss | For a small, simple program, designing classes is extra work that brings little benefit |
| A large problem is split into classes that can be written and tested separately, and by different people at the same time | Programs tend to be larger, and creating many objects uses more memory and can be slower |
| Classes can be reused in other programs, and inheritance reuses code within a program | It takes time to learn, and badly designed class structures can be hard to follow and change |
| Encapsulation protects an object’s data and lets a class’s internal code change without affecting the code that uses it | Some problems, such as a single calculation, do not divide naturally into objects, and forcing them into classes makes the design awkward |
CheckIs OOP worth it?
For which programs is an object-oriented design most worthwhile?
- A role-playing game with many characters, each with its own health, inventory and abilities
- A ten-line script that converts one temperature from Celsius to Fahrenheit
- A hospital system that manages patients, doctors, appointments and wards
- A one-off script that renames the photos in a folder by date
- A banking app maintained by a team for many years
ExamWorked exam answer
A music app stores songs. Distinguish between a Song class and a Song object.
ReviewMistakes examiners see
Using “class” and “object” as if they meant the same thing.
Describing encapsulation only as “hiding data”: it is also about keeping the data together with the methods that use it.
Giving advantages of OOP without linking them to the program in the question.
In an Evaluate answer, weigh advantages against disadvantages for the specific program and finish with a justified conclusion.
Exam practiceExam-style questions
4 questions · 13 marks. Answer each one first, then mark it yourself against the markscheme. Your answers are saved in this browser only.
A wildlife park is replacing its spreadsheets with a program. It keeps records of about 400 animals of many species, their enclosures and their feeding times, and keepers update the records every day. The park expects the program to be extended for years to come.
The Animal class has a constructor that takes a name and a weight in kg, and the methods setWeight and getWeight. After the lines shown run, the program calls z1.getWeight(). State the value returned and explain why.
Mammals, birds and reptiles are recorded in slightly different ways. Explain how inheritance could be used in the program.
Keepers ask each animal object for its daily care instructions. Outline how polymorphism would help here.
Evaluate the use of object-oriented programming for the wildlife park’s program.
0 of 4 questions marked. Mark every question to see your total.
Exam-style questions written for Praxis IB in the format of the 2027 specimen papers. They are not IB past-paper questions.