In the early stages of learning how to program most courses teach in the procedural paradigm. In the A Level course, Y12 AS exams cover only concepts associated with procedural programming. This is a programming philosophy based around these ideas:
- Programs are built from subroutines (procedures)
- Each subroutine generally performs one task
- Data is stored in global data structures and variables, or passed between subroutines through arguments and return values
- Conditional structures allow code to be skipped or run
- Iterative structures allow code blocks to be repeatedly run
The languages C and Pascal are examples of procedural languages. They are still used today, but C evolved into C++, which itself led to the development of Java and C#. Any of these languages can be used to learn the concepts of Object Oriented Programming, as can Python. Object Oriented is assessed in the full A Level in Y13, in pseudo code in the theory papers, and through your choice of language in your coursework projects.
Object Oriented
Object Oriented Programming (OOP) is built on the ideas of procedural programming, but has a fundamental difference, which is the concept of objects and the related idea of encapsulation.
To encapsulate is to put something into a capsule. For example pharmaceutical capsules contain medicine, coffee capsules contain coffee, a space capsule contains astronauts.

In OOP encapsulation is the containment of code and data within objects. The idea is that an object contains data which is operated on by its own code.
This concept of bundling up data and code together in objects may not sound like much, but it completely changes how you write programs in the OOP paradigm. Your job now as a programmer is to identify real world objects that you can model in your program.
| Procedural programming | Object Oriented programming |
| Variables: contain data | Objects: contain code & data |
| Subroutines: contain code | Classes: templates for creating objects |
Terminology
OOP comes with its own terms:
- attribute/property/field/state = variables i.e. data contained inside an object
- method/behaviour = subroutines i.e. a named block of code that can be run that belongs to an object and usually acts on its own data
- class = a template for creating objects
- object = an instance of a class
- constructor = a special method with the same name as the class which runs automatically when an object is created
- instantiation = the creation of an object from a class using the new keyword
If we were modelling a person as an object for a computer game, an attribute might be their hair colour or height. A method might be walk, which would make the person move on screen, or jump which might make the person jump.
The concept of a class is harder to grasp, but I think this video covers it well. I also like to use the analogy of a rubber stamp: the stamp itself is like a class, but once stamped on the page you have created an object. Each time you stamp on to the page you create a new instance of the class (in other words a new object).

Data hiding
Because encapsulation involves code which acts on its own data within the object, data should be protected from outside access. This is called data hiding. If we do want to allow access to data inside an object, we can provide code that allows us to read or change data.

All interactions with the data inside one object should be via the object’s methods, and even then, only some methods should be exposed to the outside world.
The object can be viewed as a black box, that provides services to the outside world via its methods, but the insides of which cannot be seen. We use the keywords private and public within class definitions to determine which methods can be seen from outside the object.
Encapsulation in practice
How can we implement encapsulation?
- Create private properties/attributes/fields (variables)
- Create public set methods to set values
- Create public get methods to retrieve values
Activity 1
- Extract the file here to a folder on your own computer.
- Double click on the package.bluej file and it should open in BlueJ.
- Click on the compile button to compile the code in Book.java.
- Use the Book class to create an object on the BlueJ workbench by right clicking on the Book class, and selecting New.
- Fill in the details for a book of your choice. Note that all of these items are strings so you should enter them inside quotes, e.g. “Harry Potter”
- When you have succesfully created an object, it will appear as a red rectangle on the object workbench at the bottom left of the screen. Double click on it to inspect its contents or right click and select “displayDetails()” to run some code.
- Create another book to see how the two objects have the same methods but different attribute values (use inspect on the object workbench).
- Study the code to see if you can identify attributes, methods, and a constructor.
Activity 2
Create a new project in BlueJ called objects1
- Create a new class in BlueJ called YearGroup.
- It should have attributes that store the year (integer) and Head of Year initials (String)
- It should have public methods that return the year, and Head of Year initials, called getYear, and getHeadOfYear respectively.
- It should have a constructor that accepts two parameters, an integer with the year group number, and a String containing the head of year’s initials.
| YearGroup |
| year headOfYear |
| YearGroup(int, String) getYear () getHeadOfYear() |
Activity 3
- Create a new class in BlueJ called Student.
- It should have attributes that store the student name (string), year group (integer) and form (char).
- It should have public methods that return the student name, year group and form, called getName, getYearGroup and getForm respectively.
- It should have a constructor that accepts two parameters name and tutorgroup. The tutorgroup parameter will take the form e.g. “11C”, where the first 1 or 2 characters are extracted and stored in the year group attribute, and the final character is extracted and stored in the form attribute.
| Student |
| name year form |
| Student(String, String) getName() getYearGroup() getForm() |
Activity 4
- Create a new class in BlueJ called Teacher.
- It should have attributes that store the teacher name (String), their number of years of service (integer), subject taught (String) and teacher initials (String)
- It should have public methods that return the name, years ofservice, subject and teacher initials, and a constructor that sets the name, initials and subject (not the years of service which should default to zero).
- It should also have a public method that allows the setting of the number of years service.
| Teacher |
| yearsOfService name initials subject |
| Teacher (String, String, String) getName() getInitials() getSubject() getYearsService() setYearsService(int) |
Knowledge check
- What does an object contain?
- What is an attribute equivalent to in procedural programming?
- What is a method?
- What is a class?
- What is the relationship between an object and class?
- Can you create more than one object from a class?
- How do you implement information hiding in OO languages?
- What is the purpose of get and set methods in OO?