直接与间接
人们对于复杂的软件系统常常有一种处理手法,即增加一层间接层,从而对系统获得一种更为灵活、满足特定需求的解决方案。

Proxy代理(结构型模式) 

 

 动机(Motivation)

在面向对象系统中,有些对象由于某种原因(比如对象创建的开销很大,或者某些操作需要安全控制,或者需要进程外的访问等),直接访问会给使用者、或者系统结构带来很多麻烦。


意图(Intent)

为其他对象提供一种代理以控制对这个对象的访问

         ---《设计模式》GoF

 

namespace Proxy1
{
    
class Emploee
    {
        
public void GetSalary() { }
        
public void Report() { }
        
public void ApplyVacation() { }
    }

    
class HrSystem
    {
        Emploee emploee 
= new Emploee();
        
public void Process() { }

    }
}

namespace Proxy2
{
    
interface IEmploee
    {
        
public void GetSalary();
        
public void Report();
        
public void ApplyVacation();
    }

    
//代理机
    class Employee : IEmploee
    {
        
public void GetSalary() { }
        
public void Report() { }
        
public void ApplyVacation() { }
    }

    
//本地
    class EmploeeProxy : IEmploee
    {
        
public void GetSalary() 
        {
            
//发送到代理处理
            
//对对象创建/访问的一种SOAP封装
            
//发送SOAP数据
            
//如果有返回值,接受返回值SOAP,解包,返回raw数据
        }
        
public void Report() { }
        
public void ApplyVacation() { }
    }
}

相关文章:

  • 2022-01-19
  • 2021-04-13
  • 2021-06-16
  • 2022-01-02
  • 2021-12-16
  • 2021-09-18
  • 2021-04-25
猜你喜欢
  • 2021-06-04
  • 2022-01-25
  • 2021-11-02
  • 2021-07-21
  • 2021-06-14
  • 2021-05-23
  • 2021-11-19
相关资源
相似解决方案