Proxy mode, so what is proxy mode? We can understand it in this way. I am very busy and I am not busy with you. If you want to contact me, please contact my agent first, the agent will always know
What can the agent do and cannot do? That is, two people have the same interface. Although the agent cannot work
Agents can work. It is very abstract. It depends on the actual situation of the instance!
For example, if Simon Qing is looking for Pan Jinlian, Pan Jinlian is embarrassed to reply. What should I do? Look for the Wang Po as an agent, as shown in the following code:
First define a type of women
Class kindwomen // indicates this type of women. Both Wang Po and Pan Jinlian belong to this type of women. {public: Virtual void happywithman () = 0; // you know, wang Po and Pan Jinlian both virtual void makeeyeswithman () = 0; // give a wink to a man, and both Wang Po and Pan Jinlian will give}; // Pan Jinlian class panjinlian: Public kindwomen {public: virtual void happywithman () {cout <"Pan Jinlian and men are happy .......... "<Endl;} virtual void makeeyeswithman () {cout <" Pan Jinlian glared at men. "<Endl ;}}; // Wang Po class Wangpo: Public kindwomen {PRIVATE: kindwomen * kindwomen; public: Virtual void happywithman () // Wang zhijiu, happy is not moving, so ask others to do {kindwomen-> happywithman ();} virtual void makeeyeswithman () // who is so ugly, so she calls someone else to throw {kindwomen-> makeeyeswithman ();} Wangpo (kindwomen * m_pkindwomen) // sets who the proxy is, wang Po began to construct {This-> kindwomen = m_pkindwomen ;}}; // Simon Qing's main function int main () {// Simon Qing saw Pan Jinlian, but Pan Jinlian was shy, I am afraid to give my eyes to him, so at this time, I need Wang Po to help him do some things and scatter Wangpo = new Wangpo (New panjinlian (); // Wang Po is playing, acting for Pan Jinlian Wangpo. makeeyeswithman (); // Wang Po began to give a wink, but in fact Pan Jinlian was throwing a wink at Wangpo. happywithman (); // Wang Po starts to be happy with men ..... in fact, Wang Po can be happy with men. Behind the scenes, Pan Jinlian is in happysystem ("pause"); Return 0 ;}
If Lu Junyi's wife wants to play with Simon Qing, he can also find Wang Po as an agent, inherit the abstract class and implement the method, and pass it to Wang Po to act as an agent, sometimes, if you need to proxy too many objects, you can also use it in the meta mode.
To sum up, the proxy mode is implemented by using interfaces and polymorphism. It encapsulates the people who need the proxy, and the people who directly come forward to do the work are agents, but what we are actually working on is the person to be represented.