码迷,mamicode.com
首页 > Windows程序 > 详细

中介者模式c#(媒婆版)

时间:2015-05-24 00:05:27      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:

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();
        }
    }
}

中介者模式c#(媒婆版)

标签:

原文地址:http://www.cnblogs.com/kexb/p/4525152.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!