Skip to content

Advanced Programming II – SS3 Digital Technologies Lesson Note (First Term)

Lesson note at a glance

Class
SS3
Subject
Digital Technologies
Term
First Term
Reading time
5 min
Start of this note, 2 of 7
Take this term’s notes offline
Reading here is free. Download all 7 SS3 Digital Technologies First term notes as PDF to print and Word to edit.
Download all three terms, ₦2,000
Instant download. Secure payment by Paystack. Card, bank transfer, USSD or OPay. Payment stuck? WhatsApp us.

Object-oriented programming (OOP) is a style of coding that groups data and actions together into objects, so that code mirrors the real world. A class is the template, and an object is an item created from that template.

Behavioural objectives

By the end of the lesson, students should be able to:

Advertisement
  1. Describe an object in terms of its properties and behaviours.
  2. Explain the difference between a class and an object.
  3. Explain encapsulation and give two reasons for using it.
  4. Explain inheritance using the terms superclass and subclass.
  5. Explain polymorphism with an example.

What is object-oriented programming?

Object-oriented programming is a style of coding where data and actions are grouped together into objects, so that programs are easier to manage.

What is procedural programming?

Procedural programming is a style of coding that gives the computer a list of instructions to follow from top to bottom.

  • Procedural code: a long list of steps, with data and functions kept apart.
  • Object-oriented code: small units called objects, each holding its own data and actions.

The real world does not work like a list. It is made up of objects.

Feature Procedural programming Object-oriented programming
Main unit Function or step Object
Data and actions Kept separate Grouped together
Best for Short, simple programs Large, complex programs
Code reuse Limited Easy, through inheritance

What are the parts of an object?

An object has two parts: properties (what it is) and behaviours (what it does).

  • Properties: the data that describes the object. They are also called attributes. Examples are colour, battery percentage and screen size.
  • Behaviours: the actions the object can perform. In code they are written as methods (functions inside a class). Examples are making a call, sending a text and taking a photo.
Object Properties Behaviours
Phone Colour, battery percentage, screen size Make a call, send a text, take a photo
Bicycle Colour, number of gears Pedal, brake, ring the bell

What is the difference between a class and an object?

A class is a blueprint that describes an object, and an object is one real item built from that blueprint.

  • Class: the template. It lists the properties and behaviours that every item of that kind will have.
  • Object: an item created from the class. It is also called an instance.
Advertisement

The house example

  • The class is the drawing: it describes what a house should look like, but you cannot sleep in it.
  • The objects are the houses: if you build 10 houses on a street from that drawing, each house is an object.
  • Different details: one house can be blue and another red, but both follow the same blueprint.
Point Class Object
Meaning Template or blueprint Item made from the template
Number needed Written once As many as you want
Real-world example House drawing A finished house
Phone example Phone (colour, battery, call) A black phone with 80% battery

What is encapsulation?

Encapsulation is the wrapping of data and methods inside a class, while hiding the inner workings from the user.

  • Microwave example: you press a button to heat food. You do not need to know how the microwave makes heat.
  • In code: the class is the “capsule”. It hides its complicated parts and shows only the methods the user needs.
  • Bank account example: the balance is hidden. You change it only through methods such as deposit and withdraw.

Why use encapsulation?

  • Safety: it prevents people from accidentally changing important data.
  • Simplicity: it makes code easier to use, because you see only what is necessary.

What is inheritance?

Inheritance is the process by which one class receives the properties and methods of another class.

  • Real-world idea: children inherit traits from their parents.
  • Code idea: a Car, a Truck and a Motorcycle can all inherit from a Vehicle class.
  • Shared properties: Vehicle holds Speed and Fuel, so the three subclasses do not repeat them.

What are a superclass and a subclass?

  • Superclass (parent): holds the general information. All vehicles move.
  • Subclass (child): inherits from the superclass and adds its own details. A car has a boot, and a motorcycle has a kickstand.
Advertisement
Vehicle Superclass Car Truck Motorcycle Subclasses
Inheritance: Car, Truck and Motorcycle are subclasses of Vehicle. Based on standard computing texts.

What are the benefits of inheritance?

  • Less typing: shared code is written once, in the superclass.
  • Easy updates: a change in the superclass reaches every subclass.
  • Clear structure: classes are arranged from general to specific.

What is polymorphism?

Polymorphism means “many shapes”: the same method name can perform different actions for different objects.

Think of the command “Speak.” The command is the same, but the result depends on who is doing the action.

Object Command Result
Dog Speak “Woof”
Cat Speak “Meow”
Human Speak “Hello”

How does polymorphism work in code?

  1. Each class has a method with the same name, for example make_sound().
  2. Each class writes its own version of that method. This is called method overriding.
  3. A list of different animal objects is created.
  4. The program calls make_sound() on every object in the list.
  5. Each object runs its own version, so the dog barks and the cat meows.

Why do programmers use object-oriented programming?

Programmers use OOP because it makes large programs easier to build, read and change.

  • Real-world model: objects match things people already understand.
  • Reuse: inheritance lets one class serve many others.
  • Safety: encapsulation protects data from accidental change.
  • Flexibility: polymorphism lets one command work on many kinds of object.

What are the key terms in object-oriented programming?

  • Class: the template or blueprint.
  • Object: the actual item created from the template, also called an instance.
  • Property: a piece of data that describes an object.
  • Method: an action an object can perform.
  • Encapsulation: hiding the inner workings for safety and simplicity.
  • Inheritance: sharing code between a parent (superclass) and a child (subclass).
  • Polymorphism: one action performing differently depending on the object.

Evaluation

  1. What two things does an object have? Give one example of each for a phone.
  2. Explain the difference between a class and an object using the blueprint and house example.
  3. What is encapsulation? State two reasons for using it.
  4. In the Vehicle example, which is the superclass and which are the subclasses?
  5. What does polymorphism mean? Give an example using the command “Speak.”

Assignment

Choose a real-world item other than a phone (for example, a bicycle or a television). List two properties and two behaviours of the item. Then explain in two or three sentences how you would describe it as a class and one object created from that class.

This term's Digital Technologies topics

SS3 First Term · 7 topics

  1. Advanced Programming I
  2. Advanced Programming II
  3. Software Development Lifecycle
  4. Networking II
  5. Cloud and Virtualization
  6. Internet of Things (IoT) Application
  7. Data Protection and Backup System
Advertisement

Lesson Notes for Other Classes

Print it or edit it in Word

Every note is free to read online. A PDF or Word copy of one subject costs ₦1,000 for one term, or ₦2,000 for all three terms.

Sign in first, then choose your class and subject at checkout.