Lesson 7 Classes and Subclasses to represent the world
After reading this lesson, you will be able to:
- Represent the world’s interactions as classes
- Design class-subclass relations
In the previous lesson, you have learned about the basics of functions in Scala. In this lesson, you’ll review classes, a fundamental concept of the object-oriented paradigm to represent interactions of the real world. Classes, subclasses, and abstract classes allow you to group entities that you can consider similar because of their shape and behavior. The concept of class in Scala is the same an in many other object-oriented languages: table 7.1 provides a quick description of the different types of classes you have in Scala. In the capstone, you’ll use a class to represent your vending machine.
Table 7.1: Summary of all the types of classes that Scala as to offer. They should look familiar to you as they match the definitions of most other object-oriented languages.
| Term |
Definition |
| Class |
A representation of items of the same kind from the real world. All its functions are fully implemented. |
| Subclass |
A class that inherits some or all of its behaviors from another class, called superclass. In Scala, a class can only up have up to a superclass. |
| Superclass |
A class whose methods are inherited by one or more classes, called subclasses. |
| Abstract Class |
A class in which one or more methods are abstract (i.e., they do not have an implementation). |