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:
Elio Struyf 2018-06-15 07:47:09 +02:00 committed by Vesa Juvonen
parent 0af385ed17
commit 10425369e9
1 changed files with 8 additions and 6 deletions

View File

@ -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;