Exemplo n.º 1
0
        static void Main(string[] args)
        {
            // The code to demonstrate the classic Prototype Pattern
            MJ player = new MJ();

            player.Health = 1;
            player.Felony = 10;
            player.Money  = 2.0;

            Console.WriteLine("Original Player stats:");
            Console.WriteLine("Health: {0}, Felony: {1}, Money: {2}",
                              player.Health.ToString(),
                              player.Felony.ToString(),
                              player.Money.ToString());

            // We enter the cheat code here and we have a new
            // player with his health fully restored.
            MJ playerToSave = player.Clone() as MJ;

            Console.WriteLine("\nCopy of player to save on disk:");
            Console.WriteLine("Health: {0}, Felony: {1}, Money: {2}",
                              playerToSave.Health.ToString(),
                              playerToSave.Felony.ToString(),
                              playerToSave.Money.ToString());

            PerformShallowCopy();

            PerformDeepCopy();

            ICloneableVersionCopy();

            // Wait for user
            Console.ReadKey();
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            // The code to demonstrate the classic Prototype Pattern
            MJ player = new MJ();
            player.Health = 1;
            player.Felony = 10;
            player.Money = 2.0;

            Console.WriteLine("Original Player stats:");
            Console.WriteLine("Health: {0}, Felony: {1}, Money: {2}", 
                player.Health.ToString(), 
                player.Felony.ToString(), 
                player.Money.ToString());

            // We enter the cheat code here and we have a new 
            // player with his health fully restored.
            MJ playerToSave = player.Clone() as MJ;            

            Console.WriteLine("\nCopy of player to save on disk:");
            Console.WriteLine("Health: {0}, Felony: {1}, Money: {2}", 
                playerToSave.Health.ToString(), 
                playerToSave.Felony.ToString(), 
                playerToSave.Money.ToString());

            PerformShallowCopy();
            
            PerformDeepCopy();

            ICloneableVersionCopy();

            // Wait for user
            Console.ReadKey();

        }