¡GoConqr estrena diseño! Cuéntanos qué te parece.

Apuntes

Sin título

vivek singh Inglés 4 páginas

Contenido del apunte (4)

Página 1

Singleton class:

1. One Object

2. Return the same object whenever we create a new instance

We use Singleton class to prevent the creation of multiple classes.

Página 2

Eagle initialization: instance created at the starting of the server in web application.

Lazy initialization: instance created during first user call.

Página 3

Factory method: it's like a class calling constructor similarliy singleton class calls factory initialization.

Returns the object of the class.

Example :

1. Runtime run = Runtime.getRuntime();

2. Calender c1 = Calender.getinstance();

Here new operator is not used to create object. But we call static method: getRuntime() and getInstance(). this return object of this classes.

Página 4

Steps to Create Singleton Class:

1. create a static variable object of type class.

2. private constructor_name(){}

3. Creating a public method known as getInstance( ) in which we will create a instance and return the object

Información

Descripción
Apunte sobre Sin título, creado por vivek singh el 04/06/2019.
Creado por
vivek singh
Visitas
0
Valoración

Escríbenos

¿Sobre qué es tu mensaje?

¿Qué te parece el nuevo diseño?

¿Te gusta?