Chapter 2. Singletons, Factories, and Builders

It may sound funny—and I may be stating the obvious—but everyone needs to be born at some point. Go ahead and have a good laugh at that. It is that obvious. Objects, too, need to be born at some point to do useful work. Objects have a lifetime as well. An object is constructed—and hopefully it does something useful before it eventually dies.

In Java we can see the object such as:

           Point p = new Point(23, 94);

We know what is going on—an object of class point is created; its constructor-invoked p is a reference to this newly created object.

At times, we want explicit control of the object-creation process. There are times when we want to allow creation of only one instance of a class. Creational design ...

Get Scala Functional Programming Patterns 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.