. Net interview-mouse, CAT and host (Observer Mode)

Source: Internet
Author: User

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 ");}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.