ASAP Understanding
- A Singleton restricts the instantiation of a class to a single instance and provides a global point of access to that instance,
- A constant is a value that cannot be changed once it is defined.
Example of a Singleton class
class Singleton {
private static instance: Singleton;
private constructor() {}
public static getInstance(): Singleton {
if (!Singleton.instance) {
Singleton.instance = new Singleton();
}
return Singleton.instance;
}
}
Example of a constant
const PI = 3.14;
Top comments (0)