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


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

  • 相关阅读:
    用Twebbrowser做可控编辑器与MSHTML(调用js)
    用Twebbrowser做可控编辑器与MSHTML(插入表格)
    用Twebbrowser做可控编辑器与MSHTML
    如何用firefox57看中国大学mooc视频
    学习EXTJS6(8)基本功能-表单的基础表字段Ext.form.field.Basic
    学习EXTJS6(7)基本功能-最常用的表单
    学习EXTJS6(6)基本功能-工具栏和菜单
    学习EXTJS6(5)基本功能-进度条组件
    学习EXTJS6(4)基本功能-信息提示框组件
    学习EXTJS6(3)基本概念
  • 原文地址:https://www.cnblogs.com/kexb/p/4525152.html
Copyright © 2020-2023  润新知