SHARE
TWEET

Proxy Pattern

Slash18 Jun 24th, 2016 (edited) 96 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2.  
  3. //    Full Tutorial on indiedevart.wordpress.com
  4.  
  5.  
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11.  
  12. namespace ConsoleApplication107
  13. {
  14.  
  15.     public interface IEquipment
  16.     {
  17.         string GetData();
  18.     }
  19.  
  20.     public class Equipment : IEquipment
  21.     {
  22.         string itemName;
  23.         public int intemId;
  24.         public Equipment()
  25.         {
  26.             itemName = "Iron Sword";
  27.             intemId = 4;
  28.         }
  29.  
  30.         public string GetData()
  31.         {
  32.             return (itemName + "   ID:  "+ intemId.ToString());
  33.         }
  34.     }
  35.  
  36.     public class EquipmentProxy : IEquipment
  37.     {
  38.         Equipment client = new Equipment();
  39.  
  40.         public string GetData()
  41.         {
  42.             if (client.intemId == 4)
  43.                 return client.GetData();
  44.  
  45.             else
  46.                 return "Item is not in inventory";
  47.         }
  48.     }
  49.  
  50.     class Program
  51.     {
  52.         static void Main(string[] args)
  53.         {
  54.             EquipmentProxy proxy = new EquipmentProxy();
  55.             Console.WriteLine("Data from Proxy: \n"+ proxy.GetData());
  56.  
  57.             Console.ReadKey();
  58.         }
  59.     }
  60. }
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