• Proxy Design Pattern 代理设计模式


    代理设计模式。此模式是用于serverclient排序。互联网接入,也经常使用的类代理,我觉得这种感觉很复杂。但是,这种设计模式本身是非常easy的。

    是一类调用另一个类的功能。客户调用类,实际工作是由另一类完成。

    式的代码:


    #include <stdio.h>
    
    class RealObj
    {
    public:
    	virtual void handleReq() = 0;
    };
    
    class DoSomething : public RealObj
    {
    public:
    	void handleReq()
    	{
    		puts("Actually, I will do the rest...");
    	}
    };
    
    class Proxy
    {
    	RealObj *subject;
    public:
    	Proxy(RealObj *sub) : subject(sub) {}
    
    	virtual ~Proxy()
    	{
    		if (subject) delete subject;
    	}
    
    	void request()
    	{
    		puts("Proxy request... using other object to requese.");
    		subject->handleReq();//Just simply call a function, using another object.
    	}
    };
    
    int main()
    {
    	RealObj *sub = new DoSomething;
    
    	Proxy p(sub);
    	p.request();
    
    	return 0;
    }

    执行:




  • 相关阅读:
    【LVS 】NAT方式实现过程
    【 LVS 】类型及算法
    [ 总结 ] RHEL6/Centos6 使用OpenLDAP集中管理用户帐号
    [ 手记 ] 关于tomcat开机启动设置问题
    [ 总结 ] nginx 负载均衡 及 缓存
    Mac
    Swift
    Swift
    Cocoapods
    Swift
  • 原文地址:https://www.cnblogs.com/gcczhongduan/p/4563011.html
Copyright © 2020-2023  润新知