This is the second project on the way to building your virtual Terrarium. The first project can be found here. If you haven't completed it yet, please start there.
In this project, we'll learn about subclasses. A subclass is an extension of an already existing class that can be used to add new behavior while also inheriting methods from its parent, the superclass. Here is an example: lets say you have a class called Car. It has properties like speed and color, and methods like drive(), stop() and blowHorn(). You can extend Car to create subclasses FlyingCar and ConvertibleCar. They will have all the methods that Car has (including constructor()!). They can also override (replace) those methods, or add completely new ones! So ConvertibleCar might add a method openRoof(). FlyingCar might override the drive(), and the stop() methods to have the car fly. The superclass Car wont have these changes. Here is what these Car classes might look like. So a subclass is a great way to re-use all the code in original class, while easily adding new capabilites. In this exercise you are going to create subclasses called EvergreenTree and RedwoodTree, and one your own design. Each will have unique traits and you'll use these subclasses to add variety and life to your forest, much like a real one! Here is an example of a completed terrarium with different species of tree. See p5 documentation here. See JS subclass documentation here. |
Directions |
||
|