Singleton Pattern - PHP Design Patterns
The singleton programming pattern solves the problem of when you need one, and only one instance of given class on your script. Although this essentially creates you a global variable, it can be very beneficial when you shouldnt have multiple instances of the same class. For example, you might not want more than one database object, since the connection goes to the same server, database, and everything else. The key to a singleton is having a private constructor that keeps your client code from instantiating the class at will. Instead, the class itself has a static, public method that creates and serves up a reference to a public, static instance variable that holds a reference to an instance of the class. Sounds confusing? Then check out the video. Its really not complicated at all.
<br>
<br>PHP Design Patterns #2
<br>
<br>Copyright (c) new Rodrigo Silveira
-
Category
No comments found