Student Hub · Technology

Object-Oriented Programming Basics

Understand classes, objects, methods, encapsulation, inheritance and abstraction through simple programming concepts.

Lesson 2 · Technology Fundamentals

Student learning object-oriented programming

What is object-oriented programming?

Object-oriented programming, commonly called OOP, is a programming approach that organizes software around objects and the data and behavior associated with those objects.

OOP is widely used in many programming languages. The exact syntax and features differ between languages, but the central concepts are broadly similar.

What is an object?

An object can represent something that a program needs to work with. It can contain data, often called properties or attributes, and behavior, commonly represented by methods.

Example

A Student object might contain a name, student ID and course information, along with methods that represent actions the student-related program needs.

What is a class?

A class can be thought of as a blueprint or definition used to create objects.

For example, a program could define a Student class and then create many Student objects using that class.

Class and object relationship

Class

Defines the structure and behavior.

Object

Represents a particular instance created from that definition.

What are attributes?

Attributes store information associated with an object. Depending on the programming language, they may also be called fields, properties or instance variables.

A Student object might have attributes such as:

  • Name
  • Student ID
  • Program
  • Semester

What are methods?

Methods represent behavior or actions that an object can perform.

For example, a BankAccount object might have methods such as deposit, withdraw or checkBalance.

Simple Model

Object = data + behavior.

Encapsulation

Encapsulation means keeping related data and behavior together while controlling how that information is accessed or modified.

A class can expose specific methods for working with internal data instead of allowing every part of a program to change that data directly.

Inheritance

Inheritance allows one class to be based on another class. A derived class can reuse or extend behavior provided by a base class, depending on the language and design.

Example

A Vehicle class could define common characteristics, while Car and Motorcycle classes could extend the general concept with more specific behavior.

Abstraction

Abstraction focuses on exposing the important functionality of something while hiding unnecessary implementation details.

A person can use a method to perform an action without needing to understand every internal operation involved in that method.

Polymorphism

Polymorphism allows related objects or classes to be handled through a common interface while providing different implementations of behavior.

For example, different types of vehicles could respond differently to the same general method, depending on the programming language and class design.

Why programmers use OOP

Object-oriented programming can help developers organize larger programs into manageable components.

Benefits may include:

  • Logical organization of related data and behavior.
  • Code reuse through appropriate class design.
  • Encapsulation of implementation details.
  • Clearer modeling of complex systems.
  • Easier maintenance when the design is well structured.

A simple mental model

Think in Three Steps

1. Define the class.

2. Create objects from the class.

3. Use the object's properties and methods.

OOP is not only about syntax

Learning object-oriented programming is not just a matter of memorizing keywords. Good object-oriented design requires understanding how classes should be structured and how different components should interact.

Students should focus on understanding the concepts first and then practice applying them in code.

Practice idea

A useful beginner exercise is to design a small library-management system.

Students might identify classes such as Book, Member and Library, then decide which attributes and methods belong to each one.

Quick review

Question 1

What is the difference between a class and an object?

Question 2

What is the purpose of a method?

Question 3

What does encapsulation help a programmer control?

Question 4

How can inheritance support reuse?

Final thoughts

Object-oriented programming gives students a useful way to think about software as interacting components that contain data and behavior.

Understanding classes, objects, methods, encapsulation, inheritance, abstraction and polymorphism provides a foundation for studying larger software systems and more advanced programming techniques.

Technology Complete

Continue to another Student Hub learning area.

Explore the cybersecurity section next or return to the Student Hub to choose another subject.