S19 · Computer Studies II · Grade 11 · ages 16–17
Object-Oriented Concepts
Classes, objects and the four principles
Grade 11 · 3.1 Object Oriented Programming (OOP) ConceptsCBE strandFree · works offline
▶ Start the interactive lessonThe full lesson adds narration, an interactive mission and a 10-question bank, and the quiz explains any mistakes.
Two ways to organise programs
Procedural programming organises a program as a sequence of functions that act on data. Object-oriented programming (OOP) bundles the data and the functions that use it into objects, modelled on real things: a student, a bank account, a matatu. Large programs are easier to manage and reuse this way. Java, C++, C# and Python all support OOP.
Classes and objects
A class is a blueprint; an object is one thing built from it. The Student class describes what every student has (attributes such as name and admission number) and can do (methods such as enrol() and pay_fees()). Amani and Wanjiru are two different objects of that one class, each with their own values.
Encapsulation and abstraction
Encapsulation bundles data and methods together and hides the inner details, so the data can only be changed through the object's own methods. A bank balance should change only through deposit() and withdraw(). Abstraction shows only what users need: you call send_money() without seeing all the steps inside.
Inheritance and polymorphism
Inheritance lets a new class reuse an existing one: Teacher and Student can both inherit name and phone from a Person class, then add their own features. Polymorphism means one method name behaves differently for each class: area() works out a circle's area one way and a rectangle's another way.
UML class diagrams
Programmers plan classes with UML (Unified Modelling Language) class diagrams: a box in three parts, holding the class name, its attributes, and its methods. Symbols show visibility: + for public, − for private, # for protected. An arrow with a hollow triangle points from a child class to its parent.
Key points
- OOP bundles data and the functions that use it into objects.
- A class is a blueprint; an object is one thing made from it.
- Attributes describe an object; methods are what it can do.
- Encapsulation hides an object's data behind its methods.
- Abstraction shows only what the user needs.
- Inheritance reuses a parent class; polymorphism lets one method act differently.
- UML class diagrams show the class name, attributes and methods.
Try it for real: Model your school
- Pick three things at school (for example Student, Teacher, Classroom) and list two attributes and two methods for each.
- Draw a UML class diagram for one of them, using + and − for public and private.