static void Main(string[] args)
        {
            WageManager wageManager = new WageManager();

            //加入WageManager观察者
            IEmployee    wagemanager             = new WageManager();
            Observerable ObserverableWageManager = new Observerable(wagemanager.GetWages);

            wageManager.Attach(ObserverableWageManager);


            //加入Manager观察者
            IEmployee    manager             = new Manager();
            Observerable ObserverableManager = new Observerable(manager.GetWages);

            wageManager.Attach(ObserverableManager);

            //加入Workder观察者
            IEmployee    worker             = new Worker();
            Observerable ObserverableWorker = new Observerable(worker.GetWages);

            wageManager.Attach(ObserverableWorker);

            //同时加入底薪3000元,分别进行计算

            wageManager.Calculate(3000);
            Console.ReadKey();
        }
Exemple #2
0
 //update
 public void update(Observerable observerable)
 {
     if (observerable == this.start)
     {
         this.startPoint = (observerable as DrawingObject).centerPoint;
     }
     else if (observerable == this.end)
     {
         this.finishPoint = (observerable as DrawingObject).centerPoint;
     }
 }
 public void Update(Observerable observable)
 {
     if (observable == this.first)
     {
         this.from = new Point((this.first.from.X + this.first.to.X) / 2, (this.first.from.Y + this.first.to.Y) / 2);
     }
     else if (observable == this.last)
     {
         this.to = new Point((this.last.from.X + this.last.to.X) / 2, (this.last.from.Y + this.last.to.Y) / 2);
     }
 }
 /// <summary>
 /// Adds an observable to the list
 /// </summary>
 /// <param name="observable"></param>
 /// <returns></returns>
 void AddObservable(Observerable observable)
 {
     /// Add Lock here
     // If the number active is at threshold, move into waiting
     if (Limit == active.Count())
     {
         waiting.Enqueue(observable);
     }
     // Else Add the observable to "active" and "observables"
     else
     {
         string URL = observable.Update();
         active[URL] = observable;
     }
 }
Exemple #5
0
 public SmallPLate(ICeramicsFactory ceramicsFactory)
 {
     this.ceramicsFactory = ceramicsFactory;
     this.observerable    = new Observerable(this);
 }
 public MediumPlate(ICeramicsFactory ceramicsFactory)
 {
     this.ceramicsFactory = ceramicsFactory;
     this.observerable    = new Observerable(this);
 }
Exemple #7
0
 //删除观察者
 public void Detach(Observerable observable)
 {
     _observableList -= observable;
 }
Exemple #8
0
 //加入观察者
 public void Attach(Observerable observable)
 {
     _observableList += observable;
 }
Exemple #9
0
 public void Add(Observerable ob)
 {
     obs.Add(ob);
 }
Exemple #10
0
 public VaseAdapter(Vase vase)
 {
     this.vase       = vase;
     this.observable = new  Observerable(this);
 }