Skip to main content

1. Introduction: From Procedural to Object-Oriented Programming

Module

1.1 8:What is Object-Oriented Programming?

Object-Oriented Programming (OOP) is a programming paradigm that organizes code around objects rather than functions and logic. An object is a data structure that contains both data (attributes) and code (methods) that operates on that data.

Key Paradigm Comparison:

AspectProcedural (C)Object-Oriented (C++)
FocusFunctions and proceduresObjects and classes
Data & FunctionsSeparateBundled together
Code OrganizationBy functionalityBy entities/objects
Data ProtectionLimited (global/local)Strong (access specifiers)
Code ReuseFunction reuseInheritance & polymorphism
MaintenanceHarder for large projectsEasier through modularity

1.2 The Four Pillars of OOP (SOLID, Encapsulation, Abstraction)

Created by: YP


Learning Objectives

After completing this module, students are expected to:

  1. ExplainEncapsulation: Bundling data and methods that operate on that data within a single unit (class), hiding internal details
  2. Abstraction: Showing only essential features while hiding implementation details
  3. Inheritance: Creating new classes from existing classes, promoting code reuse
  4. Polymorphism: Ability of objects to take many forms, allowing different implementations of the basicsame concept of OOP (Object-Oriented Programming).
  5. Differentiate between Encapsulation and Abstraction.
  6. Implement Abstract Class and Pure Virtual Function in C++.
  7. Apply fundamental SOLID principles (Single Responsibility Principle and Liskov Substitution Principle).
  8. Build a simple menu-based program using inheritance.interface

1.3 Real-World Analogy

Think of a car:

  • Object: Your specific car (e.g., a red Toyota Camry 2020)
  • Class: The blueprint/design for all Toyota Camry cars
  • Attributes (data): color, model, year, speed, fuel level
  • Methods (functions): start(), accelerate(), brake(), turn()
  • Encapsulation: You don't need to know how the engine works internally; you just use the steering wheel and pedals
  • Abstraction: The dashboard shows you speed and fuel, hiding complex engine computations