Singleton - What is your function and definition?

Asked

Viewed 721 times

2

I did some research on, I even saw some videos but, I did not understand very well the function or even how it works within Java programming. I am working on a project and a friend advised me to understand about Singleton to do the login screen. Do you have any cool material to read me? Or can one direct in this matter?

1 answer

0

This pattern allows you to create a unique object for your class within your entire application. For example, you use the class Calendar in various places of your application, accessing your instance through the method getInstance() of the same. Everywhere you are using, the instance of the Calendar It’s the same, you don’t give a new Calendar(), you use the getInstance() which is the method that makes managing the oneness of the object.

This way the Singleton standard ensures that a class has only one instance in the entire application, managing it from within the class in order to prevent another class from creating another instance.

The advantage is that the Singleton standard can be instantiated and used only when necessary, unlike if we create a global variable where the object is always created when the application is initialized and may be using resources that are not currently needed. The Singleton standard defines a single global access point and is even much easier to manage the creation and use of the instance.

More information and implementation.

Browser other questions tagged

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