Interview question: the cat cried, and all the mice started to escape. Please use OO to describe the process.
1. the mouse and the host are passive.
2. Considering linkage and scalability.
Your ownCode(Refer to the big talk Design Model -- Observer Model -- Cheng Jie)
Class program {static void main (string [] ARGs) {Cat cat = new CAT (); mouse M1 = new mouse ("Mouse 1 "); mouse m2 = new mouse ("Mouse 2"); Master M = new master (); cat. update + = new eventhandler (m1.run); cat. update + = new eventhandler (m2.run); cat. update + = new eventhandler (M. wakeup); cat. crew (); console. read () ;}//< summary> /// notification recipient interface //</Summary> interface subject {void y (); // string subjectstate {Get; set ;}} delegate void eventhandler (); // <summary> // cat class /// </Summary> class Cat: Subject {public event eventhandler update; public void crew () {console. writeline ("cat started yelling"); Policy ();} public void every Y () {Update ();}} /// <summary> /// mouse class /// </Summary> class mouse {public mouse (string name) {This. name = Name;} private string name {Get; set;} public void run () {console. writeline (name + "start to escape") ;}/// <summary> /// Primary Human /// </Summary> class master {public void wakeup () {console. writeline ("host woke up ");}}