Back to the Introduction to Computer Science outline The Course Maker
Introduction to Computer Science outline
Week 15 · Lecture outline

Week 15 — Lecture Outline · Intro to Object-Oriented Programming

Introduction to Computer Science · CSCI 1101 Fall 2026 · Prof. Okafor Fictional sample

Course: Introduction to Computer Science — CS1 / Programming Fundamentals in Python (CSCI 1101) · Silver Oak University (fictional sample) · Prof. Okafor
Objective covered: Objective 8 — Use introductory object-oriented programming: classes & objects, attributes & methods, __init__, and instances.
SLOs touched: A (define a class & create objects) · B (trace attribute/method behavior; find & fix a defect)
Meeting pattern: 2 studio sessions × 75 min = 150 min.

Every output below was produced by actually running the code in Python — not hand-traced. Run them live.


Week at a Glance

Big question "How do we bundle data and the functions that work on it into one tidy thing?"
By end of week, students can… (1) define a class with __init__; (2) give objects attributes (self.x) and methods; (3) create instances and call their methods; (4) explain self and fix the classic missing-self bug.
Key vocabulary object, class, instance, attribute, method, __init__ (constructor), self, instantiate, AttributeError
Materials slides (Deck 15), readings, the online editor + Python Tutor, one approved chatbot
Timing note 8 segments, ~150 min. Students define and run every class. This is the last new topic before the final.

Segment 1 — Hook & the Promise (8 min)

Hook. "You already use objects every day in this course. A string has data (its characters) and methods (.upper(), .split()). A list has data and methods (.append(), .sort()). Those are objects built by Python. This week you build your own."

Promise: "By Friday you'll define your own kind of object — a Dog, a BankAccount, a Rectangle — bundling its data and the functions that work on it into one tidy class."

Memory hook: "A class is the blueprint; an object is the thing you build from it."


Segment 2 — Class, Object, and __init__ (the code-along) (24 min)

Plain language. A class is a blueprint that bundles data (attributes) and behavior (methods). An object (or instance) is one specific thing built from that blueprint. __init__ is the special method that runs when you create an object — it sets up the starting attributes. self is how an object refers to itself.

Code-along — a Dog class:

class Dog:
    def __init__(self, name):      # runs when you create a Dog
        self.name = name           # store the name as an attribute

    def speak(self):               # a method
        return self.name + " says Woof!"

d = Dog("Rex")                     # create an instance
print(d.name)                      # run-verified -> Rex
print(d.speak())                   # run-verified -> Rex says Woof!

"Dog is the class (blueprint). d is an object (one dog). __init__ set d.name to 'Rex'. speak is a method — notice every method's first parameter is self, the object it's called on. We don't pass self ourselves; Python passes it for us when we write d.speak()."


Segment 3 — Attributes & Methods; More Objects (22 min)

Plain language. Attributes are an object's data (self.name); methods are functions that belong to the object and usually use its attributes.

Code-along — a Rectangle with a computed method:

class Rectangle:
    def __init__(self, w, h):
        self.width = w
        self.height = h
    def area(self):
        return self.width * self.height

r = Rectangle(3, 4)
print(r.area())        # run-verified -> 12

Code-along — a BankAccount whose method changes an attribute:

class BankAccount:
    def __init__(self, balance):
        self.balance = balance
    def deposit(self, amount):
        self.balance = self.balance + amount

a = BankAccount(100)
a.deposit(50)
print(a.balance)       # run-verified -> 150

"deposit changed the object's balance attribute. The object remembers its state between method calls — that's the power of bundling data with behavior."


Segment 4 — Each Object Is Independent (18 min) · Session 1 closes

Plain language. Each object has its own copy of the attributes. Changing one doesn't change another.

class Counter:
    def __init__(self):
        self.count = 0
    def increment(self):
        self.count = self.count + 1

c1 = Counter()
c2 = Counter()
c1.increment()
c1.increment()
c2.increment()
print(c1.count, c2.count)   # run-verified -> 2 1

"c1 and c2 are separate objects with separate count attributes — c1.count is 2, c2.count is 1. That independence is exactly why we make objects: each one carries its own state."


Segment 5 — Spot & Fix the Bug: the Missing self (20 min) · Session 2 opens

The buggy program — __init__ forgets self:

class Cat:
    def __init__(self, name):
        name = name              # BUG: not stored on the object
    def speak(self):
        return self.name + " says Meow"

c = Cat("Milo")
print(c.speak())

Run it. Run-verified: AttributeError: 'Cat' object has no attribute 'name'.
"The line name = name just assigns a local variable to itself — it never stored anything on the object. So when speak looks for self.name, there's nothing there. The fix is the self.:"

class Cat:
    def __init__(self, name):
        self.name = name         # store it ON the object
    def speak(self):
        return self.name + " says Meow"

c = Cat("Milo")
print(c.speak())                 # run-verified -> Milo says Meow

Land the idea: to store data on an object, you must write self.attribute = value. Forgetting self. is the #1 beginner OOP bug, and it shows up as an AttributeError.


Segment 6 — Why Objects? (16 min)

Plain language — objects keep big programs organized. Instead of loose variables and functions, you group related data and behavior together: a Player has health, position, and a move() method; an Email has a sender, subject, and a send() method. The object is a self-contained unit you can create many of.

Misconception + cure:
- ❌ "self is a value I pass in when I call a method."
Cure: you write d.speak() — Python passes self (the object d) automatically. You only write self in the method definition.
- ❌ "The class is the object."
Cure: the class is the blueprint; an object/instance is a specific thing built from it. One Dog class, many dog objects.


Segment 7 — Misconceptions Round-Up + Interaction (20 min)

  • "I don't need self. to store data." ✅ You do — self.x = ... stores it on the object; without it you get an AttributeError later.
  • "All objects of a class share the same attribute values." ✅ Each instance has its own (the Counter example: 2 vs 1).
  • "__init__ is something I call myself." ✅ Python calls it automatically when you create the object (Dog("Rex")).
  • "Methods are just regular functions." ✅ They belong to the object and take self first.

Interaction — predict-then-run: put a small class on a slide; have the room predict what obj.method() prints and the value of an attribute after a method call, then run it.


Segment 8 — Technology Workflow + AI-Critique, Callback & Hand-off (18 min) · Session 2 closes

Technology workflow: (1) define the class with __init__ and self.attribute = ...; (2) create an instance; (3) call its methods and print its attributes; (4) if you get AttributeError: object has no attribute 'x', you forgot self.x = ... in __init__. Visualize an object's attributes in Python Tutor.

AI-critique moment:

Ask a chatbot: "Write a BankAccount class with a deposit method, create an account with $100, deposit $50, and print the balance." Then run it: chatbots sometimes forget self. (so attributes don't stick → AttributeError), miscompute the balance, or omit __init__. The tool drafts; you run it and judge.

Callback + tease:
- Callback: "A class is a blueprint; an object bundles its own data and behavior; self ties them together."
- Tease next week: "That's the last new topic! Next week is the Final — cumulative over everything from print to objects. We'll review, and the study guide, exam-prep tutorial, and practice final are all in the module."

Hand-off: Lecture Tutorial 15; Quiz 15; Discussion 15 ("When Software Fails, Who's Responsible?"); Assignment 15 ("Build a Class"); Coding Lab 15 — "Build an Object."


Instructor FAQ — Common Stumbles

Student says / does Quick cure
Writes name = name in __init__. Use self.name = name to store it on the object, or you'll get an AttributeError.
Tries to pass self when calling a method. Don't — d.speak() passes self automatically; you only write it in the definition.
Expects two objects to share an attribute. Each instance has its own attributes (the Counter example).
Forgets __init__ entirely. Without it, the object has no starting attributes to use.
Confuses class and object. Class = blueprint; object/instance = a specific thing built from it.

Scope flag

This outline keeps OOP at the intro level: one class, __init__, attributes, methods, and instances. Inheritance, polymorphism, class vs. instance variables, dunder methods beyond __init__, encapsulation/properties, and design patterns are CS2. Python's AttributeError is referenced factually; the instructor and institution remain fictional. Every output shown was produced by running the code.

~ Prof. Okafor's edition · Fall 2026 · built with thecoursemaker.com