0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

TypeScriptでデザインパターン[5.Singleton]

Last updated at Posted at 2021-04-04

はじめに

Typescriptでデザインパターンをやっていくシリーズ(にする予定です)

結城 浩さんの「Java言語で学ぶデザインパターン入門」をTSに置き換えてTS力をあげていこうという趣旨です。

前回はこちら

メモ

  • デザパタやってもあんまりTS力上がる感じがしないな・・・

Code

namespace Singleton {
  class Singleton {
    private static singleton: Singleton = new Singleton();

    private constructor() {}
    public static getInstance(): Singleton {
      return Singleton.singleton;
    }

    public greet(): void {
      console.log('こんにちは');
    }
  }

  class Main {
    public main() {
      let instance = Singleton.getInstance();

      instance.greet();
    }
  }
  (new Main()).main();
}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?