Chapter 6. Objects

Topics in This Chapter image

6.1 Singletons — page 65

6.2 Companion Objects — page 66

6.3 Objects Extending a Class or Trait — page 67

6.4 The apply Method — page 67

6.5 Application Objects — page 68

6.6 Enumerations — page 69

Exercises — page 71

In this short chapter, you will learn when to use the object construct in Scala. Use it when you need a class with a single instance, or when you want to find a home for miscellaneous values or functions.

The key points of this chapter are:

• Use objects for singletons and utility methods.

• A class can have a companion object with the same name.

• Objects can extend classes ...

Get Scala for the Impatient now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.