What is the advantage of having a single instance when using the singleton pattern in web development?

1

Searching a little more about singleton I found some comments for and against using this approach.

I still doubt the utility of instantiating a single instance of a class (and making it global) in a web development scenario, where we should load that object between sessions.

In short, my question would be, what is the advantage or what would make a programmer choose the singleton in a web development scenario, since there is no way to create global objects between sessions. Another approach would be to instantiate a class at the beginning of the session and load it into global variables between pages.

Here in this specific scenario I mean web development using php for example.

    
asked by anonymous 07.09.2017 / 18:28

1 answer

0

The singleton pattern helps increase system performance in a web application, especially in database connections or external sources.

Instead of creating a connection every time with the Database, it will be created only once for every web instance (while not returning to the screen), reducing query time and number of connections.

    
07.09.2017 / 19:38