Other contributors have said "What is 3 Singleton class?" is the same question as "What is Singleton class?" If you believe that these are not asking the same thing and should be answered differently, click here
Answer:

Answer

"A class containing a static variable that stores a unique, and inaccesible
to external classes (private), intance of itself. The static variable is
accessed by a static method, with public access, usually called getIntance.

The static variable is initiated by the static getInstance method that
validates wether or not the static variable already exits. If the static
variable has not being initiated, a new instance of the class is created
and assigned to the static variable which reference is then returned by the
method. If the static variable was previously created, the method will
return a reference to the static variable." 1

A Singleton class is used when you wish to restrict instantiation of a class to only one object.


"Simple Singleton Pattern Example in AS3

class Data
{
private static var dataInstance:Data;

public static function getInstance():Data
{
if(!dataInstance) dataInstance = new Data();

return dataInstance;
}

public function Data()
{
if(dataInstance) throw Error("instance exists, please use Data.getInstance()");
}
}
" 2


1 [Daniel Guzman - AS3 Object Oriented Programming]
2 [Daniel Guzman - AS3 Object Oriented Programming]
First answer by Bhavanidoppalapudi. Last edit by Ddavid1415. Contributor trust: 1 [recommend contributor recommended]. Question popularity: 20 [recommend question].