abstract class Person
{
public abstract void Accept ( Action visitor) ;
}
abstract class Action
{
public abstract void GetManConclusion ( Man concreteElementA) ;
public abstract void GetWomanConclusion ( Woman concreteElementB) ;
}
class Man : Person
{
public override void Accept ( Action visitor)
{
visitor. GetManConclusion ( this ) ;
}
}
class Woman : Person
{
public override void Accept ( Action visitor)
{
visitor. GetWomanConclusion ( this ) ;
}
}
class Amativeness : Action
{
public override void GetManConclusion ( Man concreteElementA)
{
Console. WriteLine ( "男人恋爱时,不懂也要装懂" ) ;
}
public override void GetWomanConclusion ( Woman concreteElementB)
{
Console. WriteLine ( "女人恋爱时,懂也要装不懂" ) ;
}
}
class Failing : Action
{
public override void GetManConclusion ( Man concreteElementA)
{
Console. WriteLine ( "男人失败时,闷头喝酒,谁也不用劝" ) ;
}
public override void GetWomanConclusion ( Woman concreteElementB)
{
Console. WriteLine ( "女人失败时,眼泪汪汪,谁也劝不动" ) ;
}
}
class Success : Action
{
public override void GetManConclusion ( Man concreteElementA)
{
Console. WriteLine ( "男人成功时,背后多半有一个伟大的女人" ) ;
}
public override void GetWomanConclusion ( Woman concreteElementB)
{
Console. WriteLine ( "女人成功时,背后多半有一个不成功的男人" ) ;
}
}
class ObjectStructure
{
private IList< Person> elements = new List < Person > ( ) ;
public void Attach ( Person element)
{
elements. Add ( element) ;
}
public void Detach ( Person element)
{
elements. Remove ( element) ;
}
public void Display ( Action visitor)
{
foreach ( Person e in elements)
{
e. Accept ( visitor) ;
}
}
}
class Program
{
static void Main ( string [ ] args)
{
ObjectStructure structure = new ObjectStructure ( ) ;
structure. Attach ( new Man ( ) ) ;
structure. Attach ( new Woman ( ) ) ;
structure. Display ( new Failing ( ) ) ;
structure. Display ( new Amativeness ( ) ) ;
structure. Display ( new Success ( ) ) ;
}
}