Scala is a language that join both worlds “Functional Programming” and “Object Oriented”.
We talked a little bit about “Functional Programming” in the previous SKBs and today we are going to introduce the basics for “Object Oriented” : the classes and more specifically how to create an instance of a class.
We will be diving a bit more into the theory after the exercise.
A class
is a collection of functions that can be reused. This collection is created with parameters and that will make the instance
of the class behave differently.
In a lot of programming books, you will see a class
being described as a “blueprint”. And using this “blueprint”, you are able to “instantiate”, or build, an object
.
The way to build a class in Scala is using the keyword new
.
To summarize all the terminology:
new
.new
: The keyword used in Scala to instantiate a class and make an object.val
contained in the class
.def
(functions) contained in the class
.field
and method
.