Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace SingletonNoMore
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("{0} speed : {1}", "Singleton", Singleton.speed);
- Console.WriteLine("{0} speed : {1}", "Multiton", Multiton.Current.speed);
- Console.WriteLine("{0} speed : {1}", "Mergeton option 1", Mergeton.Current.speed);
- Console.WriteLine("{0} speed : {1}", "Mergeton option 2", Mergeton.speed);
- Console.ReadLine();
- }
- }
- public static class Singleton
- {
- public static float speed = 1;
- }
- public static class Multiton
- {
- //C&P'ed the Singleton instance... without 'static'.
- public class Instance { public float speed;};
- public static Instance Current = new Instance { speed = 1 };
- public static Instance Default = new Instance { speed = 0 };
- }
- public static class Mergeton
- {
- //C&P'ed the Singleton instance... without 'static'.
- public class Instance { public float speed;};
- public static Instance Current = new Instance { speed = 1 };
- public static Instance Default = new Instance { speed = 0 };
- //Magic!
- public static float speed { get { return Current.speed; } }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement