As usual the singleton is a class with behavior but CANNOT be instantiated.
Bag of Functions, with shared features. A Utils bin
In Scala you get a single instance of a class with some behavior. The
object is stateful and can hold variables that are stuck onto it. For this to work, both defintions have to be in the same file.
Had to say this to myself several times to get my head around it.
objectdefines single instance of a class
Singleton has not parameters for the constructor.
Very common in Scala. Gives you a way to build a class with static and instance methods.
Class has instance methods and fields. Object (Companion Object) has the
static methods. Unlike other paradigms, in Scala the class and instance functionality is separated. The object’s functionality is not in the scope of the class, therefore calls from class have to the begin with the name of the object: