Skip to content

Commit

Permalink
Add demo to singleton
Browse files Browse the repository at this point in the history
  • Loading branch information
torokmark committed Oct 19, 2016
1 parent 6690399 commit efb27ab
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
18 changes: 18 additions & 0 deletions singleton/src/demo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/// <reference path="singleton.ts" />
namespace SingletonPattern {
export namespace Demo {

export function show() : void {
var singleton1 = SingletonPattern.Singleton.Instance;
var singleton2 = SingletonPattern.Singleton.Instance;

if (singleton1 === singleton2) {
console.log("two singletons are equivalent");
} else {
console.log("two singletons are not equivalent");
}
}
}
}

SingletonPattern.Demo.show();
28 changes: 14 additions & 14 deletions singleton/src/singleton.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
namespace SingletonPattern {
export class Singleton {
private static instance: Singleton;

constructor() {}

static get Instance() {
if (this.instance === null || this.instance === undefined) {
this.instance = new Singleton();
}
return this.instance;
}
}
}
namespace SingletonPattern {
export class Singleton {
private static instance: Singleton;

constructor() {}

static get Instance() {
if (this.instance === null || this.instance === undefined) {
this.instance = new Singleton();
}
return this.instance;
}
}
}

0 comments on commit efb27ab

Please sign in to comment.