Dashboard/Block 3: Data Structures & OOP/Week 5
Week 5Data Structures & OOP

Classes & Objects

Okay, this week is a game-changer. Up until now, you've been writing what's called procedural code — basically a bunch of functions floating around, operating on separate chunks of data. It works, but it gets messy fast. What if you could bundle the data and the functions that work on that data into one neat package? That's Object-Oriented Programming (OOP), and it's one of the most powerful ideas in all of programming.

Here's the key concept: a class is like a blueprint. Think of yourself as an architect. You draw up plans for a house — how many rooms, where the doors go, how the plumbing works. That's your class. An object is an actual house built from those plans. You can build 10 houses from the same blueprint, each painted a different color and at a different address, but they all share the same structure.

This week, we'll cover the building blocks of OOP:

  1. -Member variables (also called fields or attributes) — the data that lives inside each object
  2. -Member functions (also called methods) — the things an object can do
  3. -Access specifiersprivate (only the class itself can touch it), public (anyone can use it), and protected (the class and its children can access it)
  4. -Constructors — special functions that set up an object the moment it's created
  5. -Initializer lists — the efficient C++ way to set member values during construction
  6. -Encapsulation — hiding the messy internals and only showing a clean interface to the outside world
TermMeaningAnalogy
ClassBlueprint defining data + behaviorArchitectural plan for a house
ObjectA specific instance of a classAn actual house built from the plan
Member variableData stored in the objectRooms, doors, windows in the house
Member functionOperations the object can performTurning on lights, opening doors
ConstructorInitializes the object when createdThe construction crew that builds the house
EncapsulationHiding internals, exposing public interfaceThe house hides its plumbing behind walls

Learning Objectives

Define classes with members and methods
Use constructors and initializer lists
Understand public, private, and protected access
Create and use objects
Understand encapsulation

Key Concepts

Classes and Objects