Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 7. Extension Design > Using and Building getInstance() Methods

Using and Building getInstance() Methods

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.



  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial