Design Pattern 6-Observer

xiaoxiao2021-03-06  63

Using system;

Namespace Pattern {///

/// summary description for class1. /// public class observer {public observer () {/// Todo: add constructor logic here //} Internal Void Update String name) {console.writeLine (name);}} public class productobj {

public productObj () {} private string name; private observer o; public string getName () {return name;} public void setName (string name) {this.name = name; // set change point notifyObservers (name);} private Void NotifyObserve (String Name) {if (o! = null) o.Update (name);} public void addobserver ({this.o = o;}}

} // Observer mode Productobj P = New Productobj (); P.AddobServer (New Observer ()); P.setname ("Good Moring");

转载请注明原文地址:https://www.9cbs.com/read-113102.html

New Post(0)