标签:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace 中介者模式
{
public abstract class Person {
public string Name { get; set; }
public string Condition { get; set; }
public abstract void getPartner(Person p);
}
public class Men : Person
{
public Mediator m
{
get;
set;
}
public Men(string name, string condition, Mediator m)
{
this.Name = name;
this.Condition = condition;
this.m = m;
m.Men = this;
}
public override void getPartner(Person p)
{
this.m.getPartner(this,p);
}
}
public class Women : Person
{
public Mediator m
{
get; set;
}
public Women(string name,string condition ,Mediator m)
{
this.Name = name;
this.Condition = condition;
this.m = m;
m.Women = this;
}
public override void getPartner(Person p)
{
this.m.getPartner(this, p);
}
}
public class Mediator
{
public Women Women { get; set; }
public Men Men { get; set; }
public void getPartner(Person w,Person m)
{
if (w.GetType() == m.GetType())
{
Console.WriteLine("我不是同性恋!");
}
else if (w.Condition == m.Condition)
{
Console.WriteLine(w.Name+"和"+m.Name+"是绝配");
}
else
{
Console.WriteLine(w.Name + "和" + m.Name + "没有门当户对");
}
}
}
class Program
{
static void Main(string[] args)
{
Mediator m = new Mediator();
Person zhangsan = new Men("张三", "5", m);
Person lisi = new Men("李四","5",m);
Person lili = new Women("莉莉","5",m);
Person lihua = new Women("李华","6",m);
zhangsan.getPartner(lisi);
zhangsan.getPartner(lihua);
lisi.getPartner(lili);
Console.ReadKey();
}
}
}
标签:
原文地址:http://www.cnblogs.com/kexb/p/4525152.html