|PHP - The benefits of the singleton [message #1753486]
||Tue, 07 February 2017 05:42
| Priti Mujumdar
Registered: February 2017
I am learning some of the codes and see the use of singletons, where it seems to me, they do not need (or do not understand because of the lack of experience). It has become a rule of etiquette. For example, in the same class database. And why should such a design is used $ class :: getInstance () -> method1 () instead of $ class :: method1 (). |
Why make the method public and to contact him through the dungeon if you can make it static? Can it be of help to reduce the load? Or, for the purpose of inheritance? As I understand, for DB Singleton only needed when the need to work with multiple databases on managed vps hosting (create an instance of the class). Or why use a singleton for the User, if the user is only one. From the obvious advantages, I do see an opportunity to implement several methods in one line, like this $ class :: getInstance () -> method1 () -> method2 () -> method2 ().
Share your experience, who use singletons and for what tasks.
[Updated on: Mon, 13 February 2017 06:53]
Report message to a moderator
Powered by FUDForum
. Page generated in 0.01284 seconds