using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace ConsoleApplication1
{
public class singleon
{
public singleon()
{
//
// TODO: 在此處添加構造函數邏輯
//
}
}
public interface XH_Subject
{
void smile(Observers obs);
}
public interface Observers
{
void say();
}
public class XH: XH_Subject
{
private ArrayList all;
public XH()
{
all = new ArrayList();
}
#region XH_Subject 成員
public void smile(Observers obs)
{
all.Add(obs);
}
#endregion
public void cry()
{
Console.WriteLine("cry and all!");
foreach (Observers obs in all)
{
obs.say();
}
}
}
public class wo: Observers
{
private string name;
public wo(string name, XH_Subject xh_sub)
{
this.name = name;
xh_sub.smile(this);
}
#region Observers 成員
public void say()
{
Console.WriteLine("say something take care of her! ");
}
#endregion
}
public class jz : Observers
{
private string name;
public jz(string name, XH_Subject xh_sub)
{
this.name = name;
xh_sub.smile(this);
}
#region Observers 成員
public void say()
{
Console.WriteLine("I fu le you!");
}
#endregion
}
class Client_Factory
{
[STAThread]
static void Main(string[] args)
{
ConsoleApplication1.XH h = new XH();
XH_Subject sub = h;
ConsoleApplication1.wo me = new wo("devil", sub);
ConsoleApplication1.jz j = new jz("N_man", sub);
h.cry();
}
}
}