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