5. Option Topic Bank

Option D: Object-oriented Programming

Option D: Object-Oriented Programming

Welcome to Option D, students! ๐ŸŽฏ In this lesson, you will learn how object-oriented programming helps programmers organize code in a way that matches real-world thinking. Instead of writing one huge block of instructions, developers can build programs from objects that represent things such as a student, a bank account, a game character, or a car ๐Ÿš—. This makes programs easier to understand, reuse, test, and modify.

By the end of this lesson, you should be able to:

  • explain the key ideas and vocabulary of object-oriented programming
  • identify and use the main features of objects and classes
  • apply simple reasoning to object-oriented program design
  • connect object-oriented programming to the wider IB Computer Science SL Option Topic Bank
  • use examples to show how object-oriented programming works in practice

What is Object-Oriented Programming?

Object-oriented programming, often shortened to OOP, is a programming style that organizes software around objects. An object is a self-contained unit that combines data and behavior. For example, a school system might have an object for a student. That object could store data like a name, age, and grade, and also have behavior like changing a password or checking attendance.

In OOP, a class is a blueprint for creating objects. If the object is the finished house ๐Ÿ , the class is the building plan. A class defines what data an object should have and what actions it should be able to perform. Many objects can be created from the same class, and each object has its own values.

Example idea:

  • Class: Car
  • Objects: one red car, one blue car, one electric car

Each car object may have properties such as color, speed, and brand, and methods such as accelerate() or brake().

This style is useful because real systems are often made of many interacting parts. OOP helps programmers model those parts clearly.


Classes, Objects, and Attributes

A class describes the structure of something. It includes attributes and methods.

  • Attributes are the data fields or properties of an object.
  • Methods are the actions or functions the object can perform.

For example, consider a class called BankAccount.

Possible attributes:

  • accountNumber
  • balance
  • ownerName

Possible methods:

  • deposit()
  • withdraw()
  • checkBalance()

A single object created from this class could represent studentsโ€™s own account at a bank app. One account object might have a balance of $250$, while another has a balance of $1000$.

The same class can create many objects, each with different values. That is important because most real programs need to handle many separate items at once.

A useful way to think about this is a school management app. The class Student might include attributes like name, ID, and classGroup, while methods might include submitAssignment() or updateProfile(). The class gives structure, and the object stores specific information for one student.


Encapsulation and Information Hiding

One of the most important ideas in OOP is encapsulation. Encapsulation means keeping data and methods together inside a class. It also means controlling access to some parts of the object so the data cannot be changed in unsafe ways.

This is often called information hiding. Some details are hidden from the user of the object, and only certain methods are allowed to interact with the internal data.

For example, in a BankAccount class, the balance should usually not be changed directly by typing a new number into the data field. Instead, the program should use methods like deposit() and withdraw(). That protects the account from invalid updates.

Why does this matter? Because it reduces errors. If the balance can only be changed through approved methods, the class can check rules such as:

  • no withdrawal if the balance is too low
  • no negative deposit amounts
  • correct update after a transaction

This is similar to a vending machine ๐Ÿค–. You do not open the machine and move money around manually. You press buttons and follow a controlled process. Encapsulation gives software that same kind of control.

In IB Computer Science, you may be expected to explain that encapsulation improves reliability and makes code easier to maintain.


Inheritance and Reuse

Another key OOP idea is inheritance. Inheritance allows one class to be based on another class. The new class, called a subclass or child class, gets attributes and methods from the original class, called the superclass or parent class.

This is useful when different objects share common features.

Example:

  • Superclass: Vehicle
  • Subclasses: Car, Bus, Motorbike

The Vehicle class might contain shared attributes like speed and weight, and shared methods like move() and stop(). The Car class could inherit those features and add its own attribute like numberOfDoors.

Inheritance saves time because you do not need to rewrite the same code again and again. It also supports clearer design because common features are stored in one place.

A real-world example is a game. A superclass called Character might include health and move(). A subclass called Wizard could inherit those features and add castSpell(). Another subclass called Archer could add shootArrow(). All characters share some basics, but each type also has special behavior.

In IB terms, inheritance is a way to support code reuse and model โ€œis-aโ€ relationships. A Car is a Vehicle, and a Wizard is a Character.


Polymorphism and Flexibility

Polymorphism means โ€œmany forms.โ€ In OOP, it allows different classes to respond to the same method name in different ways.

For example, suppose several classes all have a method named draw(). A Circle object might draw a circle, a Square object might draw a square, and a Triangle object might draw a triangle. The same method name is used, but each object behaves appropriately for its own class.

This is helpful because a program can treat different objects in a common way while still getting the correct behavior. That makes code more flexible and easier to expand.

Imagine a music app ๐ŸŽต. Different media types like Song, Podcast, and Audiobook could all have a method called play(). The app can call play() without needing separate code for every media type. Each object knows how to play itself.

Polymorphism is especially useful in large programs because it reduces complex condition checking. Instead of writing many if statements for every object type, the program can call the same method and let the object decide what to do.


OOP in Problem Solving and Design

OOP is not just a coding style. It is also a way to solve problems. A good OOP design usually starts by identifying the important objects in a situation.

For example, if students were designing a library system, possible objects might include:

  • Book
  • Member
  • Loan
  • Librarian

Then each object would need attributes and methods.

For Book:

  • attributes: title, author, ISBN, available
  • methods: markBorrowed(), markReturned()

For Member:

  • attributes: memberID, name, booksBorrowed
  • methods: borrowBook(), returnBook()

This approach helps programmers break a large problem into smaller parts. That is a strong exam skill in IB Computer Science SL because it shows structured thinking.

A common design process is:

  1. identify the objects in the problem
  2. decide what data each object needs
  3. decide what actions each object should perform
  4. choose relationships such as inheritance or association
  5. test whether the design matches the real situation

Good object-oriented design makes software easier to update. If a school later wants to add attendance tracking, a programmer can extend the Student class or add a new related class without rewriting the whole system.


How Option D Fits into the Option Topic Bank

The Option Topic Bank in IB Computer Science SL includes specialized extension topics. Option D, Object-Oriented Programming, fits this idea well because it goes beyond basic programming syntax and explores a major way of structuring software.

This topic connects to many other areas of computer science:

  • Programming fundamentals: OOP builds on variables, conditionals, loops, and functions.
  • Problem solving: it helps break complex systems into manageable parts.
  • Software development: many modern applications are designed using classes and objects.
  • Data and systems modeling: OOP models real-world entities and their interactions.

It is also useful for later study because many languages support OOP, including Java, Python, C++, and C#. Even though the syntax differs, the core ideas remain the same: classes, objects, encapsulation, inheritance, and polymorphism.

In an IB context, understanding this option helps students show deeper knowledge of how software is designed, not just how code is written line by line.


Conclusion

Object-oriented programming is a powerful way to design software by using classes and objects. It helps programmers organize data and actions together, protect important information, reuse code through inheritance, and make programs flexible through polymorphism. These ideas are central to Option D and connect strongly to the wider IB Computer Science SL Option Topic Bank.

If students can explain what a class is, how objects are created, why encapsulation matters, and how inheritance and polymorphism improve design, then students will have a strong foundation for this topic. OOP is widely used in real software because it supports clear thinking, efficient development, and maintainable programs ๐Ÿ’ก

Study Notes

  • OOP is a programming style based on objects that combine data and behavior.
  • A class is a blueprint; an object is an instance created from that blueprint.
  • Attributes store data about an object, and methods define what the object can do.
  • Encapsulation keeps data and methods together and helps control access to internal data.
  • Information hiding reduces errors by preventing direct unsafe changes to object data.
  • Inheritance lets a subclass reuse features from a superclass.
  • Inheritance supports code reuse and models โ€œis-aโ€ relationships.
  • Polymorphism means the same method name can behave differently in different classes.
  • OOP helps solve problems by breaking systems into smaller, realistic parts.
  • Common OOP examples include school systems, bank accounts, games, and library apps.
  • Option D connects to other IB topics such as programming, software design, and system modeling.
  • Many modern languages support OOP, including Java, Python, C++, and C#.

Practice Quiz

5 questions to test your understanding