Lateral thinking

Delphi gives us a very nice way to implement something that is, for all practical purposes, a singleton—an interface. An interface-based singleton doesn't strictly confront to the singleton design pattern, but we'll see later that the same property that makes it an almost singleton also gives it additional powers.

As I said before, a singleton pattern is not really a practical solution for (almost) anything. It is better to use a practical solution that is not a full singleton but can be used as one.

The singleton implementation in the Singleton_Factory unit borrows from the design patterns book and implements a Factory method design pattern. As shown next, this allows us to replace the singleton class with an interface and ...

Get Hands-On Design Patterns with Delphi now with O’Reilly online learning.

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