Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Many of the core classes in Joomla! use a special method called getInstance(). There are various ways to use this method; we will start by looking at using it to implement the singleton pattern.
We restrict the instantiation of a class to one of its own member methods by using the singleton design pattern. This enables us to create only a single instance of the class, hence the name ‘singleton’. To implement a true singleton pattern, the language must support access modifiers. If the language does not, we cannot guarantee that the class will not be instantiated from a different context. |