VCE Applied Computing: Software Development (Year 12) · Unit 3 — Programming · 18m read
Object-Oriented Programming — Classes, Objects, Encapsulation, Generalisation and Inheritance
Object-oriented programming (OOP) is a headline addition to the 2025 Software Development study design. Expect to read class designs, explain encapsulation and inheritance, and decide how to structure classes for a scenario.
Learning objective: Explain and apply object-oriented concepts — classes, objects, attributes, methods, encapsulation, generalisation and inheritance — and read simple class diagrams.
By the end of this lesson you can:
- I can describe a class and create objects (instances) from it.
- I can explain encapsulation and why attributes are often private.
- I can use generalisation and inheritance to design related classes.
A class is a cookie cutter; objects are the cookies. The cutter defines the shape once. Every cookie made from it has the same shape but its own icing — each object has the same attributes but its own values.
Classes and objects
- CLASS — a template that defines ATTRIBUTES (data) and METHODS (behaviour).
- OBJECT (instance) — a specific thing created from a class, with its own attribute values.
- CONSTRUCTOR — a special method that runs when an object is created, setting its starting values.
CLASS Account
PRIVATE owner : string
PRIVATE balance : float
METHOD deposit(amount)
IF amount > 0 THEN balance ← balance + amount ENDIF
ENDMETHOD
METHOD getBalance() RETURNS float
RETURN balance
ENDMETHOD
ENDCLASS
myAccount ← NEW Account("Lin", 0)
Encapsulation, generalisation and inheritance
ENCAPSULATION — bundling data with the methods that act on it, and HIDING the data (private attributes) so it can only be changed through controlled methods (getters and setters). In the Account example, balance cannot be set to a negative number directly — deposit() validates it. Benefits: data integrity, security and easier maintenance.
GENERALISATION — identifying the attributes and methods that several classes share and moving them into a more general SUPERCLASS (e.g. Car, Truck and Motorbike → Vehicle).
INHERITANCE — a SUBCLASS automatically receives the attributes and methods of its superclass and can add its own or override them (Truck inherits registration and speed from Vehicle and adds loadCapacity). Benefits: code reuse and consistency; changes to the superclass flow to every subclass.
Worked example (Medium)
A school system has Student and Teacher classes. Both have name, email and login(). Students also have yearLevel; teachers have faculty. Apply generalisation and inheritance.
- Generalise. Shared members move to a superclass Person: name, email, login().
- Inherit. Student and Teacher become subclasses of Person.
- Specialise. Student adds yearLevel; Teacher adds faculty.
Answer: Person (name, email, login()) ← Student (yearLevel), Teacher (faculty). Shared code is written once and reused.
Common mistakes
- Using "class" and "object" interchangeably A class is the template; an object is an instance. Fix: "Account is a class; myAccount is an object of the Account class."
- Describing encapsulation as just "putting code in a class" The key idea is controlled access to hidden data. Fix: Mention private attributes accessed through methods that can validate changes.
- Making the subclass more general than the superclass Inheritance goes from general (superclass) to specific (subclass). Fix: Ask "is a": a Truck is a Vehicle, so Truck inherits from Vehicle.
Practice questions
Making an attribute private and providing a setter method that validates input is an example of:
- Inheritance
- Encapsulation
- Generalisation
- Recursion
(1 marks)
Explain one benefit of inheritance for a programmer maintaining a large system.
(2 marks)
Distinguish between a class and an object, using an example.
(2 marks)
Summary
- Class = template of attributes and methods; object = instance with its own values.
- Encapsulation hides data behind methods that protect its integrity.
- Generalisation moves shared members into a superclass.
- Inheritance lets subclasses reuse and extend superclass code ("is a").