internal static void Main(string[] args) { Observer observer = new Observer(); List <BaseObject> objects = new List <BaseObject>(); DerivedObject1 obj1 = new DerivedObject1(); objects.Add(obj1); obj1.RegisterObserver(observer); DerivedObject2 obj2 = new DerivedObject2(); objects.Add(obj2); obj2.RegisterObserver(observer); var baseObjectObserver = new ObserverOfBase(); obj1.RegisterObserver(baseObjectObserver); obj2.RegisterObserver(baseObjectObserver); foreach (var bo in objects) { bo.FireObjectChanged(); } }
public void ObjectChanged(DerivedObject2 obj) { Console.WriteLine("DerivedObject2 Observer"); }