Chapter 6. Objects and Enumerations

Topics in This Chapter A1

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. This chapter also covers enumerated types.

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 or traits.

  • The apply method of an object is usually used for constructing new instances of the companion class.

  • If you don’t ...

Get Scala for the Impatient, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.