NOTE: Learners are introduced to the concept of classes in the world of Bug World.
In object-oriented programming, a class is a definition, or blueprint, from which new objects are created. You can think of a class as a way of "defining" what an object is, what it's characteristics are, and how it behaves
Definition: A definition, or blueprint, from which individual objects are created.
Example: Classes, similar to object-oriented programming, draw a lot of similarities to the real world. For example, think of a car. Every car has similar characteristics, such as wheels, an engine, and a body. Cars can also accelerate and turn. When an auto-maker wants to create a car, they know that car needs to have these characteristics, so they develop a blueprint for how a car is made. In programming, our form of that blueprint is a class!
Of course, there isn’t just one thing called a 'car'. There are hundreds of makes and models in different colors and shapes, however all cars still have wheels, an engine, a body, and can still accelerate and turn. In programming, we can use subclasses to create similar, yet different classes that share characteristics. Even thought they look different, both a Porsche and Mustang convertible are undeniably cars, so we would consider them subclasses of the Car class.
Application: In Bug World, the Tower class works the same way as our Car class.
Similar to the Car class, there isn't just one thing called a tower. Bug World has many different subclasses of Tower that look different, but work together similarly to defend against the Slimes.
In Kodable, there are different types of slimes that move at different paces coming toward the fuzzFamily. Learners need to choose a class to build new tower objects from. Each of these classes have different properties, so students need to think critically about the properties of their classes and choose to build towers that will best defend from the fast and slow moving Slimes.
Why We Use Classes: A class gives a programmer a simpler interface to a complex object while giving the user a common interface to use. Without classes, we couldn’t do anything in OOP! We need classes to define what objects look like and what they do in our programs.