Proxy mode-proxy program chat for you

Source: Internet
Author: User

Proxy mode analogy
Chatting with MM online, they always start with "hi, hello", "Where are you from ?" "How old are you ?" "How tall ?" These words are annoying.ProgramAs my proxy, I have set up automatic answers when I receive these words, and I will be notified to answer the questions when I receive other words. How can this problem be solved.

Proxy mode intent
Proxy mode provides a proxy for other objects to control access to this object.

Proxy mode class diagram

Proxy mode implementation
/// <Summary>
/// Defines the common interfaces of realsubject and proxy, so that proxy can be used in any place where realsubject is used.
/// </Summary>
Abstract class subject
{
Public abstract void operation ();
}

/// <Summary>
/// The real entity represented by the proxy
/// </Summary>
Class realsubject: Subject
{
Girl mm;
Public realsubject (girl mm)
{
This. Mm = mm;
}

Public override void operation ()
{
Switch (Mm. Word)
{
Case "hi, hello ":
Console. writeline ("hi, hello"); // you can specify automatic response.
Break;
Case "where did you come from? ":
Console. writeline ("Mars"); // sets automatic response
Break;
Case "How old are you? ":
Console. writeline ("18"); // sets automatic answers
Break;
Case "How tall? ":
Console. writeline ("2.5 m"); // sets automatic answers
Break;
Default: // notify me when I receive other words
Say ();
Break;
}
}

///


// I replied. Implementation:
///
private void say ()
{< br> console. writeline ("I'm playing ...... ");
}< BR >}

//


// save a realsubject reference so that the proxy can access the object and provide the same interface as the subject to replace the object
// /
class Proxy: subject
{< br> realsubject RS;
Public proxy (girl mm)
{< br> rs = new realsubject (mm );
}< br> Public override void operation ()
{< br> Rs. operation ();
}< BR >}

//


// chat mm
///
class girl
{
private string word;
Public String word
{< br> get {return word ;}< br> set {word = value ;}
}< BR >}

/// <Summary>
/// Proxy mode client application
/// </Summary>
Class Program
{
Static void main (string [] ARGs)
{
// Mm: "Hi, how are you?" Where are you from ?" "How old are you ?" "How tall ?"
Girl Mm = New Girl ();
Mm. Word = "hi, hello ";

// Proxy chat for me
Proxy proxy = new proxy (mm );
Proxy. Operation ();

Console. Read ();
}
}

Proxy mode Summary
Hey, is that the legend of chatbots! Proxy mode provides a proxy object for an object. The proxy object controls reference to the source object. An agent is an action taken by one person or structure on behalf of another person or institution. Proxy modes are everywhere, such as remote proxy, virtual proxy, Security Proxy, and intelligent guidance.

Original blog post on Zhu Liit:ArticleAddress: http://www.zhuli8.com/sjms/proxy.html

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.