Chapter 14. Singleton Pattern


In Part II, "Creating and Using the JavaScript Engine," we covered two advanced ways of creating JavaScript objects, the creation of the Ajax engine, and how to debug and put the engine to use in your web applications. We also covered extending the engine, which we will continue to do in this part of the book. I will show you how to take your Ajax applications to the next level by using design patterns in your code to help you optimize and build scalable applications that can be easily updated with future features.

Design patterns help solve common programming problems. For instance, the Singleton pattern solves the problem of having to instantiate multiple instances of an object throughout an application by simply giving our application one reference that never changes. This is how the Singleton pattern specifically solves a common programming problem. Throughout this part of the book we will learn many design patterns and how to apply them to our Ajax applications. This particular pattern is a simple one to grasp, but extremely useful. The patterns will get more advanced as we move along through the rest of Part IV "Server-Side Interaction".

Objects that utilize the Singleton pattern provide a consistent reference for other objects in the web application. A Singleton object is one that cannot be instantiated more than once. This means that multiple instances of the object cannot be created. You might be asking why you would want an object that cannot be instantiated by other objects in a web application. This chapter will explain why, help you understand how this pattern is useful, and show you how to use this pattern in your Ajax applications by creating an object that handles all of your Ajax updates.



Ajax for Web Application Developers
Ajax for Web Application Developers
ISBN: 0672329123
EAN: 2147483647
Year: 2007
Pages: 129
Authors: Kris Hadlock

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net