What it is good for?

In Scala, the singleton design pattern and static methods are implemented the same way. That's why singletons are useful for creating utility classes that have no state. Singletons in Scala can also be used to build ADTs, which we talked about in the previous chapters.

Another thing that is strictly valid for Scala is that in Scala, singletons are created in a thread-safe way out of the box and without the need to take any special care.

Get Scala Design Patterns - Second 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.