Advertisement
NPSF3000

SingletonNoMore

Oct 16th, 2012
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 KB | None | 0 0
  1. using System;
  2.  
  3. namespace SingletonNoMore
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             Console.WriteLine("{0} speed : {1}", "Singleton", Singleton.speed);
  10.             Console.WriteLine("{0} speed : {1}", "Multiton", Multiton.Current.speed);
  11.             Console.WriteLine("{0} speed : {1}", "Mergeton option 1", Mergeton.Current.speed);
  12.             Console.WriteLine("{0} speed : {1}", "Mergeton option 2", Mergeton.speed);
  13.             Console.ReadLine();
  14.         }
  15.     }
  16.  
  17.     public static class Singleton
  18.     {
  19.         public static float speed = 1;
  20.     }
  21.  
  22.     public static class Multiton
  23.     {
  24.         //C&P'ed the Singleton instance... without 'static'.
  25.         public class Instance { public float speed;};
  26.         public static Instance Current = new Instance { speed = 1 };
  27.         public static Instance Default = new Instance { speed = 0 };
  28.     }
  29.  
  30.     public static class Mergeton
  31.     {
  32.         //C&P'ed the Singleton instance... without 'static'.
  33.         public class Instance { public float speed;};
  34.         public static Instance Current = new Instance { speed = 1 };
  35.         public static Instance Default = new Instance { speed = 0 };
  36.  
  37.         //Magic!
  38.         public static float speed { get { return Current.speed; } }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement