我在看代理模式,对我而言,它似乎很像装饰器,适配器和桥模式.我误会了什么吗?有什么不同?为什么我会使用Proxy模式而不是其他模式?你过去在现实世界的项目中如何使用它们?
Facade,Proxy,Adapter和Decorator设计模式有什么区别?
我从来没有读过明确的解释,你的是什么?
我刚刚开始学习装饰设计模式,不幸的是我不得不通过各种参考来更好地理解装饰器模式,这让我非常困惑.所以,就我的理解而言,我相信这是一个装饰模式
interface IComponent
{
void Operation();
}
class Component : IComponent
{
public void Operation()
{
Console.WriteLine("I am walking ");
}
}
class DecoratorA : IComponent
{
IComponent component;
public DecoratorA(IComponent c)
{
component = c;
}
public void Operation()
{
component.Operation();
Console.WriteLine("in the rain");
}
}
class DecoratorB : IComponent
{
IComponent component;
public DecoratorB(IComponent c)
{
component = c;
}
public void Operation()
{
component.Operation();
Console.WriteLine("with an umbrella");
}
}
class Client
{
static void Main()
{
IComponent …Run Code Online (Sandbox Code Playgroud)