Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Decorator
- {
- class Program
- {
- static void Main(string[] args)
- {
- IItem newItem = new Sword();
- Console.WriteLine(newItem.GetName() + " Value: " + newItem.GetValue().ToString());
- newItem = new Magic(newItem);
- Console.WriteLine(newItem.GetName() + " Value: " + newItem.GetValue().ToString());
- Console.ReadLine();
- }
- }
- public interface IItem
- {
- string GetName();
- int GetValue();
- }
- class Sword : IItem
- {
- public string GetName()
- {
- return "Iron Sword";
- }
- public int GetValue()
- {
- return 20;
- }
- }
- class Armor : IItem
- {
- public string GetName()
- {
- return "Iron Armor";
- }
- public int GetValue()
- {
- return 50;
- }
- }
- abstract class Enchantment : IItem
- {
- IItem _item = null;
- protected int _Value = 0;
- protected Enchantment(IItem baseItem)
- {
- _item = baseItem;
- }
- public string GetName()
- {
- return (_item.GetName() +" +1 ");
- }
- public int GetValue()
- {
- return (_item.GetValue() + _Value);
- }
- }
- class Magic : Enchantment
- {
- public Magic(IItem baseComponent): base(baseComponent)
- {
- this._Value = 30;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement