SHARE
TWEET

Prototype Pattern

Slash18 Jun 29th, 2016 (edited) 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. //Full tutorial on https://indiedevart.wordpress.com/
  3.  
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9.  
  10. namespace PrototypePattern
  11. {
  12.     class Program
  13.     {
  14.         static void Main(string[] args)
  15.         {
  16.             Enemy enemy = new Enemy();
  17.             enemy.Id = 1;
  18.  
  19.             Console.WriteLine("Enemy Copy ID: " + enemy.Id.ToString());
  20.  
  21.             // We enter the cheat code here and we have a new
  22.             // player object that we can save on the disk asyncronously.
  23.             Enemy clonedEnemy = enemy.Clone() as Enemy;
  24.  
  25.             Console.WriteLine("Enemy Copy ID: " + clonedEnemy.Id.ToString());
  26.             Console.ReadLine();
  27.                
  28.         }
  29.     }
  30.     public abstract class AbstractEnemy
  31.     {
  32.         int _id;
  33.  
  34.         public int Id
  35.         {
  36.             get { return _id; }
  37.             set { _id = value; }
  38.         }
  39.         public abstract AbstractEnemy Clone();
  40.     }
  41.     class Enemy : AbstractEnemy
  42.     {
  43.         public override AbstractEnemy Clone()
  44.         {
  45.             Console.WriteLine("cloning enemy");
  46.             return this.MemberwiseClone() as AbstractEnemy;
  47.         }
  48.     }
  49.  
  50. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top