CodeIEB
Theory Notes/🗄️ Topic 4: Data & Information Management, Solution Development/11.4.5
11.4.5Grade 11

Designing Classes & OOP Principles

The core of Object-Oriented Programming — this is arguably the single most important subtopic in the whole syllabus for the practical exam and PAT.

A class is a blueprint defining the fields (data/attributes) and methods (behaviour) that its objects will have.

ConceptDescription
Field / methodA variable (field) or function (method) that belongs to a class
Static field/methodBelongs to the class itself, shared across all objects (also called a class field/method) — accessed without needing an instance
Non-static field/methodBelongs to a specific object (instance) — each object has its own copy of the value
InstanceA specific object created from a class
InstantiationThe act of creating an object from a class using the `new` keyword

Access modifiers control visibility:

ModifierMeaning
publicAccessible from anywhere, including outside the class
privateAccessible only from within the same class — the basis of encapsulation
protectedAccessible within the same class and by subclasses (see inheritance, 12.4.5)

Constant fields (final in Java) are declared once and can never be changed afterwards.

Constructors:

  • Default constructor — takes no parameters, typically sets fields to default values.
  • Parameterised constructor — accepts parameters used to set specific initial field values when the object is created.

Example

public class Learner { private String name; private int grade; // Parameterised constructor public Learner(String name, int grade) { this.name = name; this.grade = grade; } // Accessor (getter) public String getName() { return name; } // Mutator (setter) public void setGrade(int grade) { this.grade = grade; } // toString method public String toString() { return name + " (Grade " + grade + ")"; } }

Accessor method (getter)
A public method that returns the value of a private field, allowing controlled read access.
Mutator method (setter)
A public method that changes the value of a private field, allowing controlled write access (often including validation).
toString method
A method that returns a String representation of an object, commonly used for printing/debugging an object's state.
Encapsulation
Bundling fields and methods together within a class, and controlling access to that data (usually via private fields with public accessors/mutators).
Information hiding
The principle behind encapsulation — hiding an object's internal implementation details from outside code, exposing only what's necessary through a public interface.

Method overloading — defining multiple methods with the same name but different parameter lists (different number or types of parameters) within the same class.

Example

public double calculateArea(double side) { return side * side; } // for a square public double calculateArea(double length, double width) { return length * width; } // for a rectangle

Dynamic binding — the process by which the correct overloaded (or overridden — see 12.4.5) method is determined and called at runtime, based on the arguments provided or the actual object type.

Private helper methods — methods marked private that exist only to support other methods within the same class, not intended to be called from outside.

Parameter passing and return types — reusing the concepts from 10.4.6, now within the context of object methods, e.g. passing values into a constructor, or a method returning a computed field value.

Class Diagrams (UML-style) visually represent a class's fields and methods along with their access modifiers, typically using +/− symbols for public/private.

Example

Class Diagram notation: +---------------------+ | Learner | +---------------------+ | - name: String | | - grade: int | +---------------------+ | + getName(): String | | + setGrade(int): void| +---------------------+

The same class, rendered as a UML class diagram — minus (-) is private, plus (+) is public.

A class conceptually represents the backend — its logic and data exist independently of whatever user interface/frontend is used to interact with it, which is why the same class can be reused across a console app, a GUI, or even a different program entirely.

💡 Exam Tip

Encapsulation is examined constantly: expect to be asked WHY fields should be private with public accessors/mutators rather than simply public — the answer is control (validation in setters) and protection from unintended external changes.