Course 7: Six Classes - Object-oriented programming
Course overview
In this course, students learn the object-oriented programming (OOP). Using classes, you can bundle data and behavior together to make a reusable 'blueprint'. This is a core paradigm of modern software development and is essential for systematically managing large-scale projects.
Estimated time: 12-24 hours
The time required depends on the student's grade level, prior experience, and learning speed, and varies greatly. It also differs between just learning the basic concepts and moving on, versus additional practice problems or creative projects: taking those on makes a difference too. The times above are an average range, so please proceed flexibly at your child's pace.
What abilities will it build?
representing the real world as a data model. A class is a way of defining real-world concepts as data structureslike "a user has a name, email, and signup date." Database design, API design, and AI model design all require this data modeling ability.
What principles will you learn?
- (data model) By defining with a class that "a Player has health, position, and score," they learn how to model real-world concepts as data. This is the foundation of database table design.
- (data hierarchy) By expressing the relationship that "an Enemy is a kind of character" through inheritance, they learn how to relationships and hierarchies between datastructure.
AI-era thinking: computing (problem-solving) | data-driven | probabilistic thinking
Computational Thinking
| Skill | Description | Example activity |
|---|---|---|
| 🔷 Abstraction | Generalize by extracting common traits | Common traits of "all enemies" → Enemy class |
| 🌳 Hierarchy | Structure with parent/child relationships | Block → GrassBlock, StoneBlock |
| 📋 Reusable | Define once, use many times | Create 100 players from the Player class |
| 🛡️ Encapsulation | Bundle data and behavior together | Health and taking damage together |
Mathematical connections
| Math concept | Programming application | Learning benefit |
|---|---|---|
| Sets and elements | Class = set, object = element | "enemy1, an element of the Enemy set" |
| Classification and categories | Classify categories with inheritance | Animal → mammal → dog |
| Attribute | self.health = 100 |
An object's characteristic values |
| Operation/function | def attack(self): |
Actions an object performs |
Class = blueprint
Class (blueprint) Object (actual product)
┌───────────────┐ ┌───────────────┐
│ Player │ │ player1 │
│ ───────── │ → │ health: 100 │
│ health │ │ position: (0,0)│
│ position │ └───────────────┘
│ ───────── │ ┌───────────────┐
│ move() │ → │ player2 │
│ attack() │ │ health: 80 │
└───────────────┘ │ position: (5,3)│
└───────────────┘
Inheritance = extension
Block (parent class)
├── Common attributes: position, color
└── Common method: destroy()
↓ inheritance
GrassBlock (child) StoneBlock (child)
- hardness: 1 - hardness: 5
- grass color - stone color
+ grass special effect + stone special effect
Real-life classification systems
| Parent class | Child class | Common traits | difference |
|---|---|---|---|
| Animal | Dog, cat | Movement, making sound | Barking vs meowing |
| Shape | Circle, square | Area calculation | Different formulas |
| Vehicle | Car, airplane | Move | Ground vs sky |
💻 Code examples & visualization
Example 1: Player class
class Player:
"""Player class - the blueprint"""
def __init__(self, name):
"""Constructor: initialize the object"""
self.name = name
self.health = 100
self.score = 0
def take_damage(self, amount):
"""Take damage"""
self.health -= amount
def collect_coin(self):
"""Collect a coin"""
self.score += 10
# Create objects (instantiation)
player1 = Player("Cheolsu")
player2 = Player("Younghee")
Class and object relationship:
classDiagram
class Player {
+name: str
+health: int
+score: int
+take_damage(amount)
+collect_coin()
}
Player <|-- player1 : instance
Player <|-- player2 : instance
Example 2: Inheritance structure - a block system
class Block:
"""Parent class of all blocks"""
def __init__(self, x, y):
self.x = x
self.y = y
self.hardness = 1
class GrassBlock(Block):
"""Grass block"""
def __init__(self, x, y):
super().__init__(x, y)
self.hardness = 1
class StoneBlock(Block):
"""Stone block"""
def __init__(self, x, y):
super().__init__(x, y)
self.hardness = 5
Inheritance diagram:
classDiagram
Block <|-- GrassBlock
Block <|-- StoneBlock
Block <|-- WaterBlock
class Block {
+x: int
+y: int
+hardness: int
+destroy()
}
class GrassBlock {
+hardness: 1
+color: green
}
class StoneBlock {
+hardness: 5
+color: gray
}
What is object-oriented programming?
Concept explanation
Object-oriented programmingis a way of modeling the real world:
| Real world | Programming |
|---|---|
| Car blueprint | Class |
| Actual car | Object/Instance |
| Color, speed | Attributes |
| Accelerate, stop | Methods |
From a "Car" class, you can create many objects like a "red sports car" or a "blue truck."
Project 1: Digging Player - Class methods and attributes
| Item | Content |
|---|---|
| What will you learn? | Designing a player class |
| Core Concepts | Class definition, attributes, methods |
class Player:with a player's blueprintYou create. self.health = 100are the attributes (data)It is. def move(self, direction):are the methods (actions)a player can perform. Students learn the advantage of bundling data and behavior together . Even with 100 players, the same class lets you manage them in a consistent way.
init method (constructor)
| Item | Content |
|---|---|
| What will you learn? | Initializing an object |
| Core Concepts | Constructor, initialization, self |
def __init__(self):is automatically called when an object is created. Here you set the object's initial state- health 100, position (0, 0), and so on. selfmeans "this object itself," and self.healthis "this object's health." Students understand that each object has an independent state. Even if player A's health drops, player B's health is not affected.
The meaning of self
| Item | Content |
|---|---|
| What will you learn? | Understanding object references |
| Core Concepts | Instance references, method calls |
selflets a method know "which object it was called on" . player1.move()calls it, self points to player1, and player2.move()points to player2. Students learn that the same method can behave differently on different objects. This is one of the Core Concepts core ideas of object orientation. It can be confusing at first, but it becomes natural with practice.
Project 2: FPS Enemy - Classes and object creation
| Item | Content |
|---|---|
| What will you learn? | Building an enemy AI class |
| Core Concepts | Multiple instances, AI patterns |
class Enemy:an enemy's define common behaviordoes this. enemy1 = Enemy(), enemy2 = Enemy()with create multiple enemies. Each enemy independently keeps its own position, health, and state. Students learn how to efficiently manage dozens or hundreds of objectswith a single class. They also implement simple AIwhere an enemy chases the player or moves in a pattern.
Project 3: Minecraft Block - Inheritance and polymorphism
| Item | Content |
|---|---|
| What will you learn? | Extending a class |
| Core Concepts | Inheritance, polymorphism, code reuse |
Inheritanceis making a new class by extending an existing one. class GrassBlock(Block):inherits all of Block's features and inherits adds extra features. Students can create various kinds of blocks without duplicating code . Polymorphismis when the same method name behaves differentlyin each class. For example: block.break()can make a stone block break slowly and a dirt block break quickly.
Why use inheritance?
| Item | Content |
|---|---|
| What will you learn? | The principle of code reuse |
| Core Concepts | DRY principle, hierarchy |
You put common features (position, destruction, interaction) in the Block class, and GrassBlock, StoneBlock, WaterBlock, etc. inherit and extend it. Common code is written Write it only onceonce and reused in many places. Bug fixes and new features, too, only need to be done in one place and they apply to all child classes. This is the realization of the DRY(Don't Repeat Yourself) DRY principle. In large-scale projects, it's a core technique for making maintainable code.
Advantages of object-oriented programming
Why should you learn this?
- Organization: related data and behavior are bundled together
- Reusable: use a class you made once across multiple projects
- Extensibility: add new features without modifying existing code
- Collaboration: team members can each develop different classes
- Real-world modeling: naturally represent real-world concepts
Almost all modern large-scale software (games, websites, apps) is designed with object orientation.
When you finish this course...
Learning outcomes
Students will be able to:
- Define a classin a list and Create an object
__init__use to initializeselfBy using An object's attributes and methods: can access- Inheritance: extend an existing class with
- Polymorphism: understand and apply the concept of
- A game's players, enemies, and items design systematically