Private constructor in singleton (#535)
Updated the `public` constructor to `private` in singleton pattern. This prevents you from creating a new class instance outside the `ConfigurationManager`.
This commit is contained in:
parent
0af385ed17
commit
10425369e9
|
@ -1,9 +1,11 @@
|
|||
class ConfigurationManager {
|
||||
private static instance: ConfigurationManager;
|
||||
public constructor() {
|
||||
|
||||
private constructor() {
|
||||
// do something construct...
|
||||
}
|
||||
static getInstance(): ConfigurationManager {
|
||||
|
||||
public static getInstance(): ConfigurationManager {
|
||||
if (!ConfigurationManager.instance) {
|
||||
ConfigurationManager.instance = new ConfigurationManager();
|
||||
// ... any one time initialization goes here ...
|
||||
|
@ -12,17 +14,17 @@ class ConfigurationManager {
|
|||
}
|
||||
|
||||
// excercise for the reader to get data from an external data source.
|
||||
numberOfItemsPerPage(): number {
|
||||
public numberOfItemsPerPage(): number {
|
||||
return 10;
|
||||
}
|
||||
|
||||
maxNumberOfConnections(): number {
|
||||
public maxNumberOfConnections(): number {
|
||||
return 10;
|
||||
}
|
||||
|
||||
restTimeout(): number {
|
||||
public restTimeout(): number {
|
||||
return 1000;
|
||||
}
|
||||
}
|
||||
|
||||
export default ConfigurationManager;
|
||||
export default ConfigurationManager;
|
||||
|
|
Loading…
Reference in New Issue