What is the advantage of having a single instance when using the Singleton standard in web development?

Asked

Viewed 46 times

1

Researching a little more about Singleton I found some comments in favor and against the use of this approach.

But I still doubt the usefulness of instantiating a single instance of a class (and doing it globally) in a web development scenario, where we should load this object between sessions.

In short my question would be, what advantage or what would make a programmer choose 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 login and load it into the global variables between pages.

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

  • 1

    Related: https://answall.com/q/18860/57801

1 answer

0

The Singleton standard helps increase system performance in a web application, especially in connections to external databases or sources.

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.