<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="de">
	<id>https://staging.moocwiki.org/index.php?action=history&amp;feed=atom&amp;title=English%3AObject-Oriented_Programming_Basics</id>
	<title>English:Object-Oriented Programming Basics - Versionsgeschichte</title>
	<link rel="self" type="application/atom+xml" href="https://staging.moocwiki.org/index.php?action=history&amp;feed=atom&amp;title=English%3AObject-Oriented_Programming_Basics"/>
	<link rel="alternate" type="text/html" href="https://staging.moocwiki.org/index.php?title=English:Object-Oriented_Programming_Basics&amp;action=history"/>
	<updated>2026-08-28T19:24:54Z</updated>
	<subtitle>Versionsgeschichte dieser Seite in MOOCsWiki Staging</subtitle>
	<generator>MediaWiki 1.45.4</generator>
	<entry>
		<id>https://staging.moocwiki.org/index.php?title=English:Object-Oriented_Programming_Basics&amp;diff=47126&amp;oldid=prev</id>
		<title>Glanz: aiMOOC über GPT aiMOOC Action erstellt</title>
		<link rel="alternate" type="text/html" href="https://staging.moocwiki.org/index.php?title=English:Object-Oriented_Programming_Basics&amp;diff=47126&amp;oldid=prev"/>
		<updated>2026-08-27T12:16:13Z</updated>

		<summary type="html">&lt;p&gt;aiMOOC über GPT aiMOOC Action erstellt&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Neue Seite&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{T}}&lt;br /&gt;
[[Category:English]]&lt;br /&gt;
[[Category:Object-Oriented Programming Basics]]&lt;br /&gt;
&lt;br /&gt;
{{BR}}&lt;br /&gt;
= Introduction =&lt;br /&gt;
&lt;br /&gt;
Object-oriented programming, often shortened to &amp;#039;&amp;#039;&amp;#039;OOP&amp;#039;&amp;#039;&amp;#039;, is a way of organizing a program around &amp;#039;&amp;#039;&amp;#039;objects&amp;#039;&amp;#039;&amp;#039;. An object combines data with the actions that can use or change that data. OOP is used in many programming languages, including [[English:Python|Python]], [[English:Java|Java]], [[English:C Sharp|C Sharp]], and [[English:C++|C++]].&lt;br /&gt;
&lt;br /&gt;
In this course, you will learn the basic ideas of OOP by modeling familiar things such as game characters, library books, and robots. The examples use Python-like code because its syntax is readable, but the main ideas transfer to many other languages.&lt;br /&gt;
&lt;br /&gt;
[[File:ProgrammingObject.svg|500px|frameless|center]]&lt;br /&gt;
&lt;br /&gt;
The image above visualizes a programming object as a combination of attributes and methods. That combination is central to OOP.&lt;br /&gt;
&lt;br /&gt;
{{#ev:youtube|https://www.youtube.com/watch?v=SI7O81GMG2A|500|center}}&lt;br /&gt;
&lt;br /&gt;
{{BR}}&lt;br /&gt;
== Learning Goals ==&lt;br /&gt;
&lt;br /&gt;
By the end of the course, you should be able to explain the difference between a class and an object, identify attributes and methods, create simple classes and objects, use constructors to initialize objects, describe encapsulation, inheritance, abstraction, and polymorphism, read a basic [[English:Unified Modeling Language|UML]] class diagram, and decide when an object-oriented design is useful.&lt;br /&gt;
&lt;br /&gt;
{{BR}}&lt;br /&gt;
= Why Organize Programs with Objects? =&lt;br /&gt;
&lt;br /&gt;
A small program can store information in separate variables and use separate functions. As a program grows, however, it becomes harder to remember which variables belong together and which functions are allowed to change them. OOP helps group related information and behavior.&lt;br /&gt;
&lt;br /&gt;
Imagine a simple school game with several characters. Each character might have a name, a health value, and a position. Each character might also move, take damage, or speak. Instead of managing many unrelated variables, you can represent each character as one object.&lt;br /&gt;
&lt;br /&gt;
This idea is called &amp;#039;&amp;#039;&amp;#039;modeling&amp;#039;&amp;#039;&amp;#039;. You decide which parts of the real situation matter for your program and represent only those parts. A game character does not need every property of a real person. It only needs the data and behavior required by the game.&lt;br /&gt;
&lt;br /&gt;
{{BR}}&lt;br /&gt;
== Class and Object ==&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;&amp;#039;class&amp;#039;&amp;#039;&amp;#039; is a blueprint or definition. It describes what data and behavior a type of object should have. An &amp;#039;&amp;#039;&amp;#039;object&amp;#039;&amp;#039;&amp;#039; is one particular instance created from that class.&lt;br /&gt;
&lt;br /&gt;
For example, a class called &amp;#039;&amp;#039;Robot&amp;#039;&amp;#039; might describe that every robot has a name and an energy level. The objects &amp;#039;&amp;#039;Nova&amp;#039;&amp;#039; and &amp;#039;&amp;#039;Pixel&amp;#039;&amp;#039; can both be created from the Robot class, but each object can have its own values.&lt;br /&gt;
&lt;br /&gt;
[[File:CPT-OOP-objects and classes.svg|500px|frameless|center]]&lt;br /&gt;
&lt;br /&gt;
A useful comparison is a cookie cutter and cookies. The cutter represents the class: it describes a shape. Each cookie represents an object: it is a separate instance created according to that shape. The comparison is not perfect, because software objects also have behavior, but it helps distinguish a definition from an instance.&lt;br /&gt;
&lt;br /&gt;
{{BR}}&lt;br /&gt;
== Attributes and Methods ==&lt;br /&gt;
&lt;br /&gt;
An &amp;#039;&amp;#039;&amp;#039;attribute&amp;#039;&amp;#039;&amp;#039; stores information about an object. Attributes describe its current state. A robot object could have attributes such as &amp;#039;&amp;#039;name&amp;#039;&amp;#039;, &amp;#039;&amp;#039;energy&amp;#039;&amp;#039;, and &amp;#039;&amp;#039;x_position&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;&amp;#039;method&amp;#039;&amp;#039;&amp;#039; is a function that belongs to a class and describes something its objects can do. A robot might have methods such as &amp;#039;&amp;#039;move&amp;#039;&amp;#039;, &amp;#039;&amp;#039;charge&amp;#039;&amp;#039;, and &amp;#039;&amp;#039;report_status&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
[[File:OOP Classes.png|500px|frameless|center]]&lt;br /&gt;
&lt;br /&gt;
You can think of attributes as answers to questions such as “What does this object know about itself?” and methods as answers to “What can this object do?”&lt;br /&gt;
&lt;br /&gt;
{{BR}}&lt;br /&gt;
= Building Your First Class =&lt;br /&gt;
&lt;br /&gt;
The following Python example defines a small Robot class.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
class Robot:&lt;br /&gt;
    def __init__(self, name, energy):&lt;br /&gt;
        self.name = name&lt;br /&gt;
        self.energy = energy&lt;br /&gt;
&lt;br /&gt;
    def report_status(self):&lt;br /&gt;
        return f&amp;quot;{self.name} has {self.energy} energy points.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
nova = Robot(&amp;quot;Nova&amp;quot;, 80)&lt;br /&gt;
pixel = Robot(&amp;quot;Pixel&amp;quot;, 55)&lt;br /&gt;
&lt;br /&gt;
print(nova.report_status())&lt;br /&gt;
print(pixel.report_status())&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The line beginning with &amp;#039;&amp;#039;class&amp;#039;&amp;#039; creates the class definition. The lines &amp;#039;&amp;#039;nova = Robot(...)&amp;#039;&amp;#039; and &amp;#039;&amp;#039;pixel = Robot(...)&amp;#039;&amp;#039; create two separate objects. Each object has its own attribute values, even though both objects follow the same class definition.&lt;br /&gt;
&lt;br /&gt;
{{BR}}&lt;br /&gt;
== Constructors and self ==&lt;br /&gt;
&lt;br /&gt;
A &amp;#039;&amp;#039;&amp;#039;constructor&amp;#039;&amp;#039;&amp;#039; is special code used when a new object is created. In Python, the method named &amp;#039;&amp;#039;__init__&amp;#039;&amp;#039; is commonly used to initialize a new instance after it is created.&lt;br /&gt;
&lt;br /&gt;
The parameter &amp;#039;&amp;#039;self&amp;#039;&amp;#039; refers to the current object inside an instance method. In &amp;#039;&amp;#039;self.name = name&amp;#039;&amp;#039;, the value received through the parameter &amp;#039;&amp;#039;name&amp;#039;&amp;#039; is stored in the &amp;#039;&amp;#039;name&amp;#039;&amp;#039; attribute of that particular object.&lt;br /&gt;
&lt;br /&gt;
This matters because two Robot objects can hold different values at the same time. Changing &amp;#039;&amp;#039;nova.energy&amp;#039;&amp;#039; does not automatically change &amp;#039;&amp;#039;pixel.energy&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
{{BR}}&lt;br /&gt;
== Changing State with Methods ==&lt;br /&gt;
&lt;br /&gt;
Methods often change an object&amp;#039;s state. Here is an expanded version.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
class Robot:&lt;br /&gt;
    def __init__(self, name, energy):&lt;br /&gt;
        self.name = name&lt;br /&gt;
        self.energy = energy&lt;br /&gt;
&lt;br /&gt;
    def move(self, steps):&lt;br /&gt;
        cost = steps * 2&lt;br /&gt;
        if cost &amp;lt;= self.energy:&lt;br /&gt;
            self.energy -= cost&lt;br /&gt;
            return f&amp;quot;{self.name} moved {steps} steps.&amp;quot;&lt;br /&gt;
        return f&amp;quot;{self.name} does not have enough energy.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
nova = Robot(&amp;quot;Nova&amp;quot;, 20)&lt;br /&gt;
print(nova.move(4))&lt;br /&gt;
print(nova.energy)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;move&amp;#039;&amp;#039; method checks the object&amp;#039;s energy before changing it. This is more controlled than allowing every part of a program to change the energy value in any way it wants.&lt;br /&gt;
&lt;br /&gt;
{{BR}}&lt;br /&gt;
= Encapsulation and Abstraction =&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Encapsulation&amp;#039;&amp;#039;&amp;#039; means keeping related data and behavior together and controlling how an object&amp;#039;s internal state is accessed or changed. The purpose is not simply to hide everything. It is to create a clear boundary around an object&amp;#039;s responsibilities.&lt;br /&gt;
&lt;br /&gt;
For example, a BankAccount class might provide &amp;#039;&amp;#039;deposit&amp;#039;&amp;#039; and &amp;#039;&amp;#039;withdraw&amp;#039;&amp;#039; methods instead of allowing any part of the program to set the balance to any value. The methods can check rules before changing the balance.&lt;br /&gt;
&lt;br /&gt;
[[File:150€-Machine.svg|500px|frameless|center]]&lt;br /&gt;
&lt;br /&gt;
This educational diagram invites you to think about a machine from the outside. You can use its allowed controls without needing to know every internal detail. That leads to a related idea: &amp;#039;&amp;#039;&amp;#039;abstraction&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
Abstraction means showing the important features of something while leaving unnecessary internal detail out of the way. When you call a method such as &amp;#039;&amp;#039;robot.move(3)&amp;#039;&amp;#039;, you use a simple interface. You do not need to think about every line inside the method each time you call it.&lt;br /&gt;
&lt;br /&gt;
{{#ev:youtube|https://www.youtube.com/watch?v=iLRZi0Gu8Go|500|center}}&lt;br /&gt;
&lt;br /&gt;
{{BR}}&lt;br /&gt;
== Public Interfaces and Internal Details ==&lt;br /&gt;
&lt;br /&gt;
A class&amp;#039;s &amp;#039;&amp;#039;&amp;#039;public interface&amp;#039;&amp;#039;&amp;#039; is the set of operations that other parts of the program are expected to use. A good interface makes valid actions easy and invalid actions harder.&lt;br /&gt;
&lt;br /&gt;
Different OOP languages enforce access rules differently. Java and C++ have explicit access modifiers such as &amp;#039;&amp;#039;public&amp;#039;&amp;#039; and &amp;#039;&amp;#039;private&amp;#039;&amp;#039;. Python relies more on naming conventions and properties, although it also has mechanisms that discourage direct access to some names. The general design idea is the same: decide which parts of an object should be used from outside and which parts are implementation details.&lt;br /&gt;
&lt;br /&gt;
[[File:UML class diagram with access modifiers.svg|500px|frameless|center]]&lt;br /&gt;
&lt;br /&gt;
{{BR}}&lt;br /&gt;
= Inheritance =&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Inheritance&amp;#039;&amp;#039;&amp;#039; allows one class to build on another class. The more general class is often called a &amp;#039;&amp;#039;&amp;#039;base class&amp;#039;&amp;#039;&amp;#039;, &amp;#039;&amp;#039;&amp;#039;parent class&amp;#039;&amp;#039;&amp;#039;, or &amp;#039;&amp;#039;&amp;#039;superclass&amp;#039;&amp;#039;&amp;#039;. A more specific class that inherits from it is often called a &amp;#039;&amp;#039;&amp;#039;subclass&amp;#039;&amp;#039;&amp;#039; or &amp;#039;&amp;#039;&amp;#039;child class&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
Suppose a game has different kinds of characters. All characters have a name and health, but a Wizard also has magic points. You can model the shared parts once and extend them.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
class Character:&lt;br /&gt;
    def __init__(self, name, health):&lt;br /&gt;
        self.name = name&lt;br /&gt;
        self.health = health&lt;br /&gt;
&lt;br /&gt;
    def describe(self):&lt;br /&gt;
        return f&amp;quot;{self.name} has {self.health} health.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
class Wizard(Character):&lt;br /&gt;
    def __init__(self, name, health, magic):&lt;br /&gt;
        super().__init__(name, health)&lt;br /&gt;
        self.magic = magic&lt;br /&gt;
&lt;br /&gt;
    def cast_spell(self):&lt;br /&gt;
        return f&amp;quot;{self.name} casts a spell.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
merlin = Wizard(&amp;quot;Merlin&amp;quot;, 90, 60)&lt;br /&gt;
print(merlin.describe())&lt;br /&gt;
print(merlin.cast_spell())&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The Wizard class inherits the &amp;#039;&amp;#039;name&amp;#039;&amp;#039;, &amp;#039;&amp;#039;health&amp;#039;&amp;#039;, and &amp;#039;&amp;#039;describe&amp;#039;&amp;#039; behavior from Character, then adds &amp;#039;&amp;#039;magic&amp;#039;&amp;#039; and &amp;#039;&amp;#039;cast_spell&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
[[File:UML virtual inheritance.svg|500px|frameless|center]]&lt;br /&gt;
&lt;br /&gt;
Inheritance can reduce repetition when the relationship truly means “is a kind of.” However, inheritance should not be used only because two classes happen to share a few lines of code. Sometimes composition is a better design.&lt;br /&gt;
&lt;br /&gt;
{{BR}}&lt;br /&gt;
== Composition: Has-a Relationships ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Composition&amp;#039;&amp;#039;&amp;#039; means building an object by giving it other objects as parts. A Car &amp;#039;&amp;#039;has an&amp;#039;&amp;#039; Engine, so composition is usually a more natural model than saying a Car &amp;#039;&amp;#039;is an&amp;#039;&amp;#039; Engine.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
class Engine:&lt;br /&gt;
    def start(self):&lt;br /&gt;
        return &amp;quot;Engine started.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
class Car:&lt;br /&gt;
    def __init__(self):&lt;br /&gt;
        self.engine = Engine()&lt;br /&gt;
&lt;br /&gt;
    def start(self):&lt;br /&gt;
        return self.engine.start()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A useful design question is: “Is this object a special kind of the other object, or does it contain or use the other object?” The first can suggest inheritance; the second can suggest composition.&lt;br /&gt;
&lt;br /&gt;
{{BR}}&lt;br /&gt;
= Polymorphism =&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Polymorphism&amp;#039;&amp;#039;&amp;#039; means that different kinds of objects can respond to the same operation in their own way. The word comes from roots meaning “many forms.”&lt;br /&gt;
&lt;br /&gt;
Consider two classes that both provide a &amp;#039;&amp;#039;speak&amp;#039;&amp;#039; method.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
class Dog:&lt;br /&gt;
    def speak(self):&lt;br /&gt;
        return &amp;quot;Woof!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
class Cat:&lt;br /&gt;
    def speak(self):&lt;br /&gt;
        return &amp;quot;Meow!&amp;quot;&lt;br /&gt;
&lt;br /&gt;
animals = [Dog(), Cat()]&lt;br /&gt;
&lt;br /&gt;
for animal in animals:&lt;br /&gt;
    print(animal.speak())&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The loop calls the same method name, &amp;#039;&amp;#039;speak&amp;#039;&amp;#039;, on each object. The result depends on the actual object. This lets programs work with a common interface without needing a separate instruction for every possible class.&lt;br /&gt;
&lt;br /&gt;
Polymorphism can appear in several forms depending on the language. At this level, the most important idea is that code can send the same kind of message or method call to different objects and receive behavior appropriate to each object.&lt;br /&gt;
&lt;br /&gt;
{{BR}}&lt;br /&gt;
= Reading a UML Class Diagram =&lt;br /&gt;
&lt;br /&gt;
[[English:Unified Modeling Language|UML]] is a visual language used to model software systems. A basic UML class diagram often shows a class as a box with compartments.&lt;br /&gt;
&lt;br /&gt;
[[File:ClassTemplateUML.svg|500px|frameless|center]]&lt;br /&gt;
&lt;br /&gt;
The top compartment contains the class name. The middle compartment usually lists attributes. The bottom compartment usually lists operations or methods. Lines and arrows can show relationships such as inheritance, association, or composition.&lt;br /&gt;
&lt;br /&gt;
[[File:UML class diagram example.svg|500px|frameless|center]]&lt;br /&gt;
&lt;br /&gt;
You do not need to memorize every UML symbol to benefit from class diagrams. For Grades 9–10, focus first on identifying classes, important attributes, important methods, and clear relationships.&lt;br /&gt;
&lt;br /&gt;
{{BR}}&lt;br /&gt;
== From a Problem to a Class Model ==&lt;br /&gt;
&lt;br /&gt;
Suppose you are designing a school library app. A useful first model might include Book, Member, and Loan.&lt;br /&gt;
&lt;br /&gt;
A Book might store a title, author, and availability state. A Member might store a name and member identifier. A Loan might connect one Book to one Member for a period of time. Methods could include &amp;#039;&amp;#039;borrow&amp;#039;&amp;#039;, &amp;#039;&amp;#039;return_book&amp;#039;&amp;#039;, and &amp;#039;&amp;#039;is_overdue&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
Before writing code, ask three questions: What objects exist in the problem? What information must each object remember? What actions should each object be responsible for? These questions help turn a real situation into a software model.&lt;br /&gt;
&lt;br /&gt;
{{BR}}&lt;br /&gt;
= A Complete Mini-Project: Digital Pet =&lt;br /&gt;
&lt;br /&gt;
This example combines several OOP ideas in one small program.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
class DigitalPet:&lt;br /&gt;
    def __init__(self, name):&lt;br /&gt;
        self.name = name&lt;br /&gt;
        self._hunger = 5&lt;br /&gt;
&lt;br /&gt;
    def feed(self):&lt;br /&gt;
        self._hunger = max(0, self._hunger - 2)&lt;br /&gt;
        return f&amp;quot;{self.name} has been fed.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
    def status(self):&lt;br /&gt;
        return f&amp;quot;{self.name} has hunger level {self._hunger}.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
class FlyingPet(DigitalPet):&lt;br /&gt;
    def fly(self):&lt;br /&gt;
        return f&amp;quot;{self.name} flies through the air.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
pets = [DigitalPet(&amp;quot;Milo&amp;quot;), FlyingPet(&amp;quot;Sky&amp;quot;)]&lt;br /&gt;
&lt;br /&gt;
for pet in pets:&lt;br /&gt;
    print(pet.status())&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The class &amp;#039;&amp;#039;DigitalPet&amp;#039;&amp;#039; defines shared data and behavior. Each instance has its own name and hunger state. The &amp;#039;&amp;#039;feed&amp;#039;&amp;#039; method controls how hunger changes, which illustrates encapsulation. &amp;#039;&amp;#039;FlyingPet&amp;#039;&amp;#039; inherits from &amp;#039;&amp;#039;DigitalPet&amp;#039;&amp;#039; and adds new behavior. A collection can store objects from related classes and treat them through shared methods.&lt;br /&gt;
&lt;br /&gt;
{{#ev:youtube|https://www.youtube.com/watch?v=e4fwY9ZsxPw|500|center}}&lt;br /&gt;
&lt;br /&gt;
{{BR}}&lt;br /&gt;
= Common Mistakes and Debugging =&lt;br /&gt;
&lt;br /&gt;
A common beginner mistake is confusing a class with an object. Remember that the class is the definition, while an object is one instance.&lt;br /&gt;
&lt;br /&gt;
Another mistake is forgetting that each object has its own state. If two objects unexpectedly affect each other, check whether you accidentally used shared class data when you intended separate instance data.&lt;br /&gt;
&lt;br /&gt;
A third mistake is creating a class for every noun in a problem. Good modeling is selective. Create classes when they help group meaningful data and behavior.&lt;br /&gt;
&lt;br /&gt;
Inheritance can also be overused. If the relationship does not clearly mean “is a kind of,” consider composition. Good OOP is not about using the largest number of classes. It is about making responsibilities and relationships understandable.&lt;br /&gt;
&lt;br /&gt;
When debugging, inspect one object at a time. Check the values of its attributes before and after a method call. Trace which method runs. Test small examples before combining many objects.&lt;br /&gt;
&lt;br /&gt;
{{BR}}&lt;br /&gt;
= OOP and Other Programming Styles =&lt;br /&gt;
&lt;br /&gt;
OOP is one programming paradigm, not the only one. &amp;#039;&amp;#039;&amp;#039;Procedural programming&amp;#039;&amp;#039;&amp;#039; organizes a program mainly around procedures or functions and sequences of steps. &amp;#039;&amp;#039;&amp;#039;Functional programming&amp;#039;&amp;#039;&amp;#039; emphasizes functions, expressions, and controlled data transformation. Real programs often combine ideas from more than one paradigm.&lt;br /&gt;
&lt;br /&gt;
OOP is especially useful when a problem contains entities with state and behavior that interact over time. A graphical game, simulation, school management system, or user interface can often be modeled naturally with objects. For a tiny calculation, OOP may add unnecessary complexity.&lt;br /&gt;
&lt;br /&gt;
The goal is not to decide that OOP is always best. The goal is to understand its tools well enough to choose them when they improve a program&amp;#039;s structure.&lt;br /&gt;
&lt;br /&gt;
{{BR}}&lt;br /&gt;
= Interactive Tasks =&lt;br /&gt;
&lt;br /&gt;
{{BR}}&lt;br /&gt;
== Quiz: Test Your Knowledge ==&lt;br /&gt;
&lt;br /&gt;
{{MC}}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;What is a class in object-oriented programming?&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
(A blueprint that defines data and behavior for objects)&lt;br /&gt;
(!A single value stored in a variable)&lt;br /&gt;
(!A loop that repeats instructions)&lt;br /&gt;
(!A file containing only pictures)&lt;br /&gt;
&lt;br /&gt;
{{E}}&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{MC}}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;What is an object?&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
(An instance created from a class)&lt;br /&gt;
(!A comment that explains code)&lt;br /&gt;
(!A programming language)&lt;br /&gt;
(!A rule that stops all methods)&lt;br /&gt;
&lt;br /&gt;
{{E}}&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{MC}}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;What does an attribute usually represent?&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
(Data or state belonging to an object)&lt;br /&gt;
(!A video embedded in a page)&lt;br /&gt;
(!A mistake in program syntax)&lt;br /&gt;
(!A command that ends every program)&lt;br /&gt;
&lt;br /&gt;
{{E}}&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{MC}}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;What is a method?&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
(A function associated with a class or object)&lt;br /&gt;
(!A picture of a class diagram)&lt;br /&gt;
(!A number that cannot change)&lt;br /&gt;
(!A name for every programming language)&lt;br /&gt;
&lt;br /&gt;
{{E}}&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{MC}}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;What is a main purpose of encapsulation?&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
(To control access to related data and behavior)&lt;br /&gt;
(!To remove every class from a program)&lt;br /&gt;
(!To make every attribute global)&lt;br /&gt;
(!To replace methods with comments)&lt;br /&gt;
&lt;br /&gt;
{{E}}&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{MC}}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;What does inheritance allow a subclass to do?&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
(Build on data and behavior defined by a more general class)&lt;br /&gt;
(!Erase all methods from its parent)&lt;br /&gt;
(!Turn every object into a string)&lt;br /&gt;
(!Prevent objects from storing state)&lt;br /&gt;
&lt;br /&gt;
{{E}}&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{MC}}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;What does polymorphism allow?&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
(Different objects to respond to the same operation in their own way)&lt;br /&gt;
(!Only one object to exist in a program)&lt;br /&gt;
(!Every class to have exactly one method)&lt;br /&gt;
(!All attributes to store identical values)&lt;br /&gt;
&lt;br /&gt;
{{E}}&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{MC}}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Which relationship is best described by composition?&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
(A car has an engine)&lt;br /&gt;
(!A wizard is a character)&lt;br /&gt;
(!A cat is an animal)&lt;br /&gt;
(!A square is a shape)&lt;br /&gt;
&lt;br /&gt;
{{E}}&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{MC}}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;What does a UML class diagram help you represent?&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
(Classes attributes methods and relationships)&lt;br /&gt;
(!Only the colors used in an interface)&lt;br /&gt;
(!Only the order of keyboard keys)&lt;br /&gt;
(!The speed of a computer processor)&lt;br /&gt;
&lt;br /&gt;
{{E}}&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{MC}}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;When is object-oriented design especially useful?&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
(When a problem has interacting entities with state and behavior)&lt;br /&gt;
(!Whenever a program contains only one calculation)&lt;br /&gt;
(!Only when no functions are allowed)&lt;br /&gt;
(!Only when the program has no data)&lt;br /&gt;
&lt;br /&gt;
{{E}}&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{BR}}&lt;br /&gt;
== Memory Game ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;memo-quiz&amp;quot;&amp;gt;&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| Class || Blueprint that defines a type of object&lt;br /&gt;
|-&lt;br /&gt;
| Object || Individual instance created from a blueprint&lt;br /&gt;
|-&lt;br /&gt;
| Attribute || Stored state belonging to an instance&lt;br /&gt;
|-&lt;br /&gt;
| Method || Behavior that an instance can perform&lt;br /&gt;
|-&lt;br /&gt;
| Constructor || Setup code used when creating an instance&lt;br /&gt;
|-&lt;br /&gt;
| Abstraction || Focus on essential features while hiding unnecessary detail&lt;br /&gt;
|}&lt;br /&gt;
{{E}}&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{BR}}&lt;br /&gt;
== Drag and Drop ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;lueckentext-quiz&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Match the correct terms.&lt;br /&gt;
! Topic&lt;br /&gt;
|-&lt;br /&gt;
| &amp;#039;&amp;#039;&amp;#039;Class blueprint&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
| Defines shared attributes and methods&lt;br /&gt;
|-&lt;br /&gt;
| &amp;#039;&amp;#039;&amp;#039;Object instance&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
| Stores its own current state&lt;br /&gt;
|-&lt;br /&gt;
| &amp;#039;&amp;#039;&amp;#039;Encapsulation boundary&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
| Controls how internal data is accessed&lt;br /&gt;
|-&lt;br /&gt;
| &amp;#039;&amp;#039;&amp;#039;Inheritance relationship&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
| Connects a specialized class to a more general class&lt;br /&gt;
|-&lt;br /&gt;
| &amp;#039;&amp;#039;&amp;#039;Polymorphic method call&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
| Produces behavior based on the actual object&lt;br /&gt;
|}&lt;br /&gt;
{{E}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
Match each OOP idea with the explanation that best describes it.&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{BR}}&lt;br /&gt;
== Crossword Puzzle ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div class=&amp;quot;kreuzwort-quiz&amp;quot;&amp;gt;&lt;br /&gt;
{|&lt;br /&gt;
|-&lt;br /&gt;
| Encapsulation || Which principle controls access to an object&amp;#039;s internal state?&lt;br /&gt;
|-&lt;br /&gt;
| Inheritance || Which principle lets a specialized class build on a general class?&lt;br /&gt;
|-&lt;br /&gt;
| Polymorphism || Which principle allows one operation to have different object-specific behavior?&lt;br /&gt;
|-&lt;br /&gt;
| Constructor || What initializes a new object&amp;#039;s starting state?&lt;br /&gt;
|-&lt;br /&gt;
| Attribute || What stores a piece of state inside an object?&lt;br /&gt;
|-&lt;br /&gt;
| Method || What do you call a behavior defined by a class?&lt;br /&gt;
|}&lt;br /&gt;
{{E}}&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{BR}}&lt;br /&gt;
== LearningApps ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;iframe&amp;gt; https://learningapps.org/index.php?s=Object-Oriented+Programming+Basics &amp;lt;/iframe&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{BR}}&lt;br /&gt;
== Cloze Text ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;quiz display=simple&amp;gt;&lt;br /&gt;
{&amp;#039;&amp;#039;&amp;#039;Complete the text.&amp;#039;&amp;#039;&amp;#039;&amp;lt;br&amp;gt;&lt;br /&gt;
|type=&amp;quot;{}&amp;quot;}&lt;br /&gt;
A { class } is a blueprint that defines data and behavior for a type of object. An { object } is one instance created from that blueprint. Information stored in an object is often called an { attribute }. A function that belongs to a class is called a { method }. A constructor helps establish an object&amp;#039;s initial { state }. { Encapsulation } creates a boundary around related data and behavior. { Inheritance } lets a specialized class build on a more general class. { Polymorphism } allows different objects to respond to the same operation in their own way. A simple { UML } class diagram can show classes, attributes, methods, and relationships.&lt;br /&gt;
&amp;lt;/quiz&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{BR}}&lt;br /&gt;
= Open-Ended Tasks =&lt;br /&gt;
&lt;br /&gt;
{{BR}}&lt;br /&gt;
=== Easy ===&lt;br /&gt;
# [[English:Class Hunt|Class Hunt]]: Find five everyday examples that could be modeled as classes, and for each one write two possible attributes and two possible methods.&lt;br /&gt;
# [[English:Object Cards|Object Cards]]: Create paper or digital cards for three objects from the same class and give each object different attribute values.&lt;br /&gt;
# [[English:Robot Class|Robot Class]]: Write or sketch a simple Robot class with a name, an energy attribute, and two methods, then explain what each part does.&lt;br /&gt;
# [[English:UML Sketch|UML Sketch]]: Draw a one-class UML diagram for a Book, including at least three attributes and three methods.&lt;br /&gt;
&lt;br /&gt;
{{BR}}&lt;br /&gt;
=== Standard ===&lt;br /&gt;
# [[English:Digital Pet Project|Digital Pet Project]]: Build a small DigitalPet program with a constructor, at least three attributes, and methods that safely change the pet&amp;#039;s state.&lt;br /&gt;
# [[English:Interview a Programmer|Interview a Programmer]]: Interview a programmer, computing teacher, or advanced student about where they use classes and objects, then summarize the most useful example in your own words.&lt;br /&gt;
# [[English:Inheritance Design|Inheritance Design]]: Design a superclass and at least two subclasses for a game, school, or transport system, and explain why each subclass has an is-a relationship with the superclass.&lt;br /&gt;
# [[English:OOP Explainer Video|OOP Explainer Video]]: Produce a two-to-four-minute video that teaches class, object, attribute, and method using one clear real-world analogy and one code example.&lt;br /&gt;
&lt;br /&gt;
{{BR}}&lt;br /&gt;
=== Advanced ===&lt;br /&gt;
# [[English:Library Model|Library Model]]: Design a small library system with at least four interacting classes, justify the responsibilities of each class, and show the relationships in a UML diagram.&lt;br /&gt;
# [[English:Composition Investigation|Composition Investigation]]: Compare an inheritance-based and composition-based design for the same feature, implement or diagram both, and argue which design is easier to extend.&lt;br /&gt;
# [[English:Polymorphism Experiment|Polymorphism Experiment]]: Create at least three classes that respond differently to the same method call, run a test collection of their objects, and explain why the calling code does not need separate instructions for every class.&lt;br /&gt;
# [[English:Refactor a Program|Refactor a Program]]: Find or write a short procedural program, redesign it with classes where appropriate, test both versions, and evaluate whether the object-oriented version improves clarity or creates unnecessary complexity.&lt;br /&gt;
&lt;br /&gt;
{{:Open Task - Create a MOOC}}&lt;br /&gt;
&lt;br /&gt;
{{BR}}&lt;br /&gt;
= Learning Assessment =&lt;br /&gt;
&lt;br /&gt;
# [[English:Modeling Challenge|Modeling Challenge]]: Given a description of a school event app, identify suitable classes, attributes, methods, and relationships, then justify why each belongs in your model.&lt;br /&gt;
# [[English:Code Reasoning|Code Reasoning]]: Examine a short program with two objects from the same class, predict the state of each object after several method calls, and explain your reasoning step by step.&lt;br /&gt;
# [[English:Encapsulation Review|Encapsulation Review]]: Redesign a class whose data can be changed to invalid values from anywhere in the program, then explain how your public methods protect the object&amp;#039;s valid state.&lt;br /&gt;
# [[English:Inheritance or Composition|Inheritance or Composition]]: For three proposed class relationships, decide whether inheritance, composition, or neither is most suitable and defend each choice using is-a and has-a reasoning.&lt;br /&gt;
# [[English:Polymorphism Transfer|Polymorphism Transfer]]: Design a new example in which unrelated or related objects share a common method name, and explain how polymorphism could simplify the code that uses those objects.&lt;br /&gt;
# [[English:Design Evaluation|Design Evaluation]]: Compare an object-oriented solution and a procedural solution to the same small problem, using criteria such as readability, reuse, testability, and unnecessary complexity.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{BR}}&lt;br /&gt;
= Evidence of Learning =&lt;br /&gt;
&lt;br /&gt;
Strong evidence of learning includes accurate explanations of class, object, attribute, method, constructor, encapsulation, abstraction, inheritance, composition, and polymorphism; correct creation of multiple objects with independent state; working methods that read or change state predictably; sensible use of a constructor; a UML diagram that matches the intended program structure; code or pseudocode that demonstrates at least one relationship between classes; test cases that show expected and unexpected inputs; explanations of design choices rather than only finished code; a project product such as a digital pet, game model, library model, diagram, interview summary, or explainer video; and the ability to transfer OOP ideas to a new problem and judge whether OOP is appropriate.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{BR}}&lt;br /&gt;
= OERs on the Topic =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;iframe&amp;gt; https://en.m.wikipedia.org/wiki/Object-oriented_programming &amp;lt;/iframe&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The English Wikipedia article on [[English:Object-oriented programming|Object-oriented programming]] provides a broader reference for the paradigm, its terminology, history, and related concepts. You can also explore [[English:Class (computer programming)|Class (computer programming)]], [[English:Object (computer science)|Object (computer science)]], [[English:Encapsulation (computer programming)|Encapsulation (computer programming)]], [[English:Inheritance (object-oriented programming)|Inheritance (object-oriented programming)]], [[English:Polymorphism (computer science)|Polymorphism (computer science)]], and [[English:Unified Modeling Language|Unified Modeling Language]] as follow-up topics.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{BR}}&lt;br /&gt;
= Linked Learning Areas =&lt;br /&gt;
&lt;br /&gt;
{| align=center&lt;br /&gt;
{{:D-Tab}}&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;[[English:Object-Oriented Programming Basics|Object-Oriented Programming Basics]]&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
# [[English:Object-oriented programming|Object-oriented programming]]&lt;br /&gt;
# [[English:Class (computer programming)|Class (computer programming)]]&lt;br /&gt;
# [[English:Object (computer science)|Object (computer science)]]&lt;br /&gt;
# [[English:Method (computer programming)|Method (computer programming)]]&lt;br /&gt;
# [[English:Encapsulation (computer programming)|Encapsulation (computer programming)]]&lt;br /&gt;
# [[English:Inheritance (object-oriented programming)|Inheritance (object-oriented programming)]]&lt;br /&gt;
# [[English:Polymorphism (computer science)|Polymorphism (computer science)]]&lt;br /&gt;
# [[English:Unified Modeling Language|Unified Modeling Language]]&lt;br /&gt;
# [[English:Python|Python]]&lt;br /&gt;
# [[English:Software design|Software design]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[Category:English]]&lt;br /&gt;
[[Category:Object-Oriented Programming Basics]]&lt;br /&gt;
[[Category:Computer Science]]&lt;br /&gt;
[[Category:Programming]]&lt;br /&gt;
[[Category:Software Engineering]]&lt;br /&gt;
[[Category:Information Technology]]&lt;br /&gt;
[[Category:Grades 9-10]]&lt;br /&gt;
&lt;br /&gt;
{{BR}}&lt;br /&gt;
= aiMOOC Projects =&lt;br /&gt;
[[Category:English]]&lt;br /&gt;
[[Category:Object-Oriented Programming Basics]]&lt;br /&gt;
[[Category:Computer Science]]&lt;br /&gt;
[[Category:Programming]]&lt;br /&gt;
[[Category:Software Engineering]]&lt;br /&gt;
[[Category:Information Technology]]&lt;br /&gt;
[[Category:Grades 9-10]]&lt;br /&gt;
[[Category:AI_MOOC]]&lt;br /&gt;
[[Category:GPT aiMOOC]]&lt;br /&gt;
{{MT}}&lt;/div&gt;</summary>
		<author><name>Glanz</name></author>
	</entry>
</feed>