中介者模式 C#

   相亲的时候如果有个媒婆,那么就会避免很多不必要的麻烦了撒。

 

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApplication1
{
class Program
{

public abstract class Person
{
public string Name
{
get;
set;
}

public string Condition
{
get;
set;
}

public abstract void GetPartner(Person p);
}

public class Mediator
{
public Women Women
{
get;
set;
}

public Man Man
{
get;
set;
}

public void GetPartner(Person w, Person m)
{
if (w.GetType() == m.GetType())
{
Console.WriteLine("same sex");
}
else if (w.Condition == m.Condition)
{
Console.WriteLine(w.Name + " and " + m.Name + " match");
}
else
{
Console.WriteLine(w.Name + " and " + m.Name + " not match");
}
}
}

public class Man:Person
{
public Mediator Mediator
{
get;
set;
}

public Man(string name, string condition, Mediator m)
{
this.Name = name;
this.Condition = condition;
this.Mediator = m;
Mediator.Man = this;
}

public override void GetPartner(Person p)
{
this.Mediator.GetPartner(this, p);
}
}

public class Women : Person
{
public Mediator Mediator
{
get;
set;
}

public Women(string name, string condition, Mediator m)
{
this.Name = name;
this.Condition = condition;
this.Mediator = m;
m.Women = this;
}

public override void GetPartner(Person p)
{
this.Mediator.GetPartner(this, p);
}
}

static void Main(string[] args)
{
Mediator m = new Mediator();
Person zk = new Man("zk", "5", m);
Person yzl = new Women("yzl", "5", m);

zk.GetPartner(yzl);
}
}
}

转载于:https://www.cnblogs.com/zkzk945/p/5121294.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值