Level 1: Object‐Oriented Programming - IncrediCoders/Python1 GitHub Wiki

GitHubAvatarPoint

Grafika Turtle added this page on March 14, 2025


Here is a bonus article that will tell you more about Object‐Oriented Programming!

In addition to this bonus article, you can find other bonus articles that teach you the topics I covered in Level 1: Syntax, Troubleshooting & Error Handling, Methods, Turtle Graphics, and Comments.

Learn About Object‐Oriented Programming

Object-Oriented Programming, or OOP, is a way of thinking about and organizing code by using objects. An object is like a real-world thing in your program. It can have information like a name or color and do things like move or speak.

Instead of writing one long list of instructions, OOP helps you group related things together. You can imagine each object as a mini-helper in your program, with its own job.

Why Object-Oriented Programming Matters

OOP makes big programs easier to build and understand. Each object is responsible for its own part, so you don’t get confused trying to manage everything at once.

For example, you’re one student (an object), and so is Paul Python. You each have your own backpack, class schedule, and favorite snack. You’re both students, but you’re still different from each other. That’s how objects work—same kind of thing, but each one is unique.

Principles of Organizing Code

OOP uses four core principles to organize code as consistently and efficiently as possible:

  • Encapsulation keeps important parts of code together safely, so others can only use them in the right way. For example, think about Paul’s father’s car. The car has a big engine and lots of parts inside, but Paul doesn't need to touch those. He just uses the steering wheel and pedals to drive. That’s encapsulation—the car hides the engine and complicated stuff and gives you simple controls to use it safely. If the engine was exposed, then the car (and the passengers) could be at risk. In programming, we do the same thing. We put important data inside a class and only allow people to use it through safe buttons, like methods. This keeps everything clean and protected, so that no one accidentally breaks the program, just like exposing the engine might do damage to the car.

  • Abstraction is hiding the messy and complicated details and only showing the simple parts that are needed. For example, imagine a student using a tablet at IncrediCoders Academy. The tablet does many smart things like loading apps and running code, but the student doesn’t see all that. They just open Visual Studio Code, write Python, and click Run. That’s abstraction—the tablet hides all the tricky things and only shows what the student needs to see. In programming, we use abstraction to make things simple by showing only the important parts and hiding everything else behind the scenes. Similarly, in the IncrediCoders: Python Adventures book, we use the concept of abstraction even with the Init.py files, where some of the classes and lines of code are hidden, so that you can focus on the code that you need to write when you make the game!

  • Polymorphism helps objects take on many forms. The same action can work in different ways. It means the same thing can behave differently, depending on the situation, making programs more flexible and easier to manage. For example, think about Paul Python. At home, he is a son who helps his father. At school, he is a student who listens to Mrs. Scratcher and does his homework. With his friend Grafika Turtle, he is a teammate who plays coding games. Paul is the same person, but he acts differently in each role. That’s polymorphism—one object, many forms. In programming, we do the same thing. We use one method name, like draw(). Then, the programmer can use the same method in very different ways. It keeps the code clean, organized, and adaptable.

  • Inheritance uses features from one class in another. It helps make programs easier to build and maintain by allowing one class to reuse features from another, instead of rewriting the same code. For example, think about Paul Python and his father—they are both very similar in appearance and structure, and that’s because Paul inherits some of his physical body features from his father, like the color of his body. That’s inheritance—one object receiving built-in traits from another. In programming, we create a parent class with common features, and other classes inherit those features automatically, keeping the code clean, reusable, and easy to work with.

Python Example

You can think of an object as something in your program that has a name and can do things. Let’s create an object that represents a pet and let it say hello.

Scenario: Paul Python has a pet named Bubbles. He wants Bubbles to say hello.

class Pet:
    def __init__(self, name):
        self.name = name

    def say_hello(self):
        print("Hi, I'm " + self.name + "!")

# Create the pet object
bubbles = Pet("Bubbles")
bubbles.say_hello()

This will print: Hi, I'm Bubbles!

In this example:

  • Pet is the object type.
  • Bubbles is the object.
  • say_hello is something the object can do.

This shows how Object-Oriented Programming helps group things together—Bubbles knows its own name and how to say hello!

Comparing Programming Languages

Most modern programming languages use Object-Oriented Programming. The way objects are made can look different, but the goal is the same: break your program into smaller parts that do specific jobs.

Imagine a game character who has a name and can jump. Let’s compare how different languages handle that object’s data and action:

Python

class Character:
    def __init__(self, name):
        self.name = name

    def jump(self):
        print(self.name + " jumps!")

Java

public class Character {
    String name;

    public Character(String name) {
        this.name = name;
    }

    public void jump() {
        System.out.println(name + " jumps!");
    }
}

C#

public class Character {
    public string name;

    public Character(string name) {
        this.name = name;
    }

    public void Jump() {
        Console.WriteLine(name + " jumps!");
    }
}

What's the difference?

  • All three languages use OOP to group information and actions into one object.
  • Python uses simpler words like self and doesn’t need to say the type (like string).
  • Python relies on indentations for the class structure, rather than curly braces.
  • Java and C# require more structure, but they follow the same idea: keep related things together.

Object-Oriented Programming is like organizing your code into a team of helpers. Each one knows what to do and handles their own job, just like your classmates at IncrediCoders Academy.

Learn More

TBD

Next Steps

Next, if you need help completing the Turtle Map project in the book, you can find help at Level 1: Help.

After you complete Level 1 in the book, you can also take on the two extra challenges to add to your Turtle Map program and learn more! When you're done, you can move on to Level 2, the Class Introductions program!

Take the Challenges!

  1. Challenge 1: On this page, I show you how to map a different route to our school, the IncrediCoders Academy. This time, we're going to cross the bridge, over the lake.

  2. Challenge 2: For this challenge, I'll show you how to create a loop, so that you can have the turtle go back and forth between my house and the school, five times.

More Level 1 Resources

In addition to this Bonus Article and the instructions for our Level 1 challenges, we also have Online Articles, a Learning Quiz, an Unplugged Activity, and a Rewards article:

  • Level 1: Online Articles - I made you a list of different web pages I found, which will help you learn more about Turtle Graphics.

  • Level 1: Learning Quiz - I wrote some questions in case you want to quiz yourself about what you learned. Or you can teach others and quiz them! You'll find the answers to the quiz in the Level 1 Solutions folder.

  • Level 1: Unplugged Activity - I wrote this page with more details than what you saw in the book. In this game, you'll have one person act as the Turtle, and one person is the Programmer!

  • Level 1: Rewards - If you completed the Turtle Map project that we talked about in the car, then I set up this page to be your reward. You can see some illustrations of me and learn more about who I am! You'll also find the Turtle Award digital download, to show off your accomplishment!

Level 2

After you're completely done with Level 1 (did you do the challenges?), then it's time to move on to Level 2! While you read through Level 2 in your book, you can check out the resources from Mrs. Scratcher, as she teaches you how to build the Class Introductions program:

I hope you had fun learning about the concept of Syntax! After all, my brother was named after it!

-- Grafika Turtle

⚠️ **GitHub.com Fallback** ⚠️