Agent mode (proxy)

Source: Internet
Author: User

1, because my home from the railway station is very far, so every time to buy fire tickets are to those selling train ticket agent there to buy train tickets, so the use of proxy mode

2. The proxy mode is generally designed to these nouns

abstract role: Common interface for declaring real objects and proxy objects;  

proxy role: The proxy object role contains a reference to the real object, allowing you to manipulate the real object, At the same time, the proxy object provides the same interface as the real object to replace the real object at any moment. At the same time, the proxy object can attach other actions when performing the real object operation, which is equivalent to encapsulating the real object.  

real role: The real object represented by the proxy role is the object we end up referencing.

3, actual case

Pan Jinlian find Simon Qing, that Pan Jinlian embarrassed, what to do, find that the king of the agent, performance in the program is such embodiment of

First talk about the elements of this scene: a type of woman, Pan Jinlian, Wang, we are hypothetical, and then Pan Jinlian to find Simon Qing happy, but Pan Jinlian embarrassed directly, find a Wang Po agent bai.

4, specific code

Abstract role: Real object, proxy object interface class iwoman{public:virtual void mklove () = 0;virtual void watch () = 0;};/ /real Role: The real object represented by the proxy role is the object that we end up referencing, really the character class Panjinlian:p ublic iwoman{public:void mklove () {cout << pan Jinlian in and that man ... "<< Endl;} void Watch () {cout << "Pan Jinlian in a movie with a man" << endl;}};/ /proxy Role: The Proxy object class, the proxy object must contain a reference to the true object, and the proxy object provides the same interface as the real object so that at any time class Wangpo:p ublic iwoman{private:iwoman *women;public: Wangpo () {women = new Panjinlian ();} void Mklove () {women->mklove ();} void Watch () {Women->watch ();}}; int _tmain (int argc, _tchar* argv[]) {//Pan Jinlian, want ML, because embarrassed, so look for the king of the Wangpo wp;//surface look actually is Wang in happy in fact is pan Jinlian in Cool Wp.mklove (); Cin.get (); return 0;}
5, slowly realize .....

Agent mode (proxy)

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.