Mediator Mode C # (Matchmaker edition)

Source: Internet
Author: User

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Text;

Namespace Broker mode
{
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's Men {get; set;}
public void Getpartner (person W,person m)
{
if (w.gettype () = = M.gettype ())
{
Console.WriteLine ("I'm not gay!") ");

}
else if (w.condition = = m.condition)
{
Console.WriteLine (w.name+ "and" +m.name+ "are perfect Match");
}
Else
{
Console.WriteLine (W.name + "and" + M.name + "no good match");
}

}

}
Class Program
{
static void Main (string[] args)
{
Mediator m = new Mediator ();
Person Zhangsan = new Men ("Zhang San", "5", m);
Person Lisi = new Men ("John Doe", "5", m);
Person Lili = new Women ("Lily", "5", m);
Person Lihua = new Women ("Li Hua", "6", m);
Zhangsan.getpartner (Lisi);
Zhangsan.getpartner (Lihua);
Lisi.getpartner (Lili);

Console.readkey ();
}
}
}

Mediator Mode C # (Matchmaker edition)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.