コード例 #1
0
 // This is the getInstance method of the singleton.
 public static Hand PickUpObject(HoldableItem heldItem)
 {
     if (handInstance == null)
     {
         handInstance = new Hand(heldItem);
     }
     return(handInstance);
 }
コード例 #2
0
ファイル: Form1.cs プロジェクト: j-runser/SingletonDemo
        public Form1()
        {
            InitializeComponent();

            rock  = new HoldableItem("Rock", 2.0);
            stick = new HoldableItem("Stick", 1.0);
            dirt  = new HoldableItem("Dirt", 0.5);
        }
コード例 #3
0
 // This is the instantiation, it is private to fit the model for the
 // singleton design pattern.
 private Hand(HoldableItem heldItem)
 {
     // Same as in Java differnt in C++
     this.heldItem = heldItem;
 }