タグ

singletonに関するterurouのブックマーク (3)

  • C# in Depth: Implementing the Singleton Pattern

    Table of contents (for linking purposes...) Introduction Non-thread-safe version Simple thread safety via locking Double-checked locking Safety through initialization Safe and fully lazy static initialization Lazy<T> Exceptions Performance Conclusion Introduction The singleton pattern is one of the best-known patterns in software engineering. Essentially, a singleton is a class which only allows a

    terurou
    terurou 2013/06/09
    thread-safeなSingletonがほしい場合はLazy<T>を使うと良い
  • JavaとSingletonとLazyLoad - _development,

    久しぶりにSingletonを自前で書こうとしたら書き方を忘れていた。 のでググったりを見たりしながら思い出した。 なんとなく以下の二点を覚えていたので、そのあたりの記憶を頼りに。 HogeHogeHolder的な内部クラスを使っていた LazyLoad(遅延初期化)になっていた Effective Javaから 「Effective Java, 第2版, Joshua Bloch, 2008」にSingletonパターンの記載がある。 ひとつはPublic finalのフィールドによるSingleton。 package com.undrdevelopment.singleton; public class Elvis { public static final Elvis INSTANCE = new Elvis(); private Elvis() { } } もうひとつはstat

    JavaとSingletonとLazyLoad - _development,
    terurou
    terurou 2011/05/18
    リスト10の書き方でインスタンスの生成が遅延されるのか。知らんかった
  • Pythonでシングルトンを実装するには? - Mixnuts@BetaNews

    クラスが使える言語の場合、クラス インスタンスが1つしか生成されないシングルトン(Singleton)が便利なケースがあります。ある解説書(『Expert Python Programming』:Tarek Ziade著)によれば、 Singleton restricts instantiation of a class to one object. シングルトンは、クラスのインスタンス化を単一オブジェクトに規制する。と書かれています。では、Pythonでどのように実装するのか? というのが今回のお話。 最低限のクラス定義 まずは、題材にする最低限の機能しか持たないクラスを定義してみましょう。 class Singleton(object): def __new__(clsObj, *args, **kwargs): instance = super(Singleton, object).

    Pythonでシングルトンを実装するには? - Mixnuts@BetaNews
  • 1