using System;
using System.Collections.Generic;
using System.Text;
namespace 装饰模式
{
class Person
{
public Person()
{
}
private string name;
public Person(string name)
{
this.name = name;
}
public virtual void Show()
{
Console.WriteLine("装扮的{0}", name);
}
}
class Finery : Person
{
protected Person component;
//打扮
public void Decorate(Person component)
{
this.component = component;
}
public override void Show()
{
if (component != null)
{
component.Show();
}
}
}
class TShirts : Finery
{
public override void Show()
{
Console.Write("大T-Shirt ");
base.Show();
}
}
class BigTrouser : Finery
{
public override void Show()
{
Console.Write("垮裤 ");
base.Show();
}
}
class Sneakers: Finery
{
public override void Show()
{
Console.Write("破球鞋 ");
base.Show();
}
}
class Program
{
static void Main(string[] args)
{
Person ps = new Person("小江");
Sneakers sn = new Sneakers();
BigTrouser bt = new BigTrouser();
TShirts ts = new TShirts();
sn.Decorate(ps);
bt.Decorate(sn);
ts.Decorate(bt);
ts.Show();
}
}
}