zoukankan      html  css  js  c++  java
  • 适配器模式 vs 装饰者模式 vs 代理模式

    Reference

    [1] https://refactoring.guru/design-patterns/adapter

    1. Adapter Design Pattern 适配器模式

    Adapter is a structural design pattern, which allows incompatible objects to collaborate.

    You can create an adapter. This is a special object that converts the interface of one object so that another object can understand it.

    When adapter receives a call to any of its methods, it translates parameters to appropriate format and then directs the call to one or several methods of the wrapped object.

    Examples could be found here https://refactoring.guru/design-patterns/adapter/java/example

    2. Decorator 装饰者模式

    Decorator is a structural design pattern that lets you attach new behaviors to objects by placing these objects inside special wrapper objects that contain the behaviors.

    Wrapper is the alternative nickname for the Decorator pattern that clearly expresses the main idea of the pattern. A “wrapper” is an object that can be linked with some “target” object. The wrapper contains the same set of methods as the target and delegates to it all requests it receives. However, the wrapper may alter the result by doing something either before or after it passes the request to the target.

    Examples could be found herehttps://refactoring.guru/design-patterns/decorator/java/example

    3. Proxy 代理模式

    Proxy is a structural design pattern that provides an object that acts as a substitute for a real service object used by a client. Proxy receives client requests, does some work (access control, caching, etc.) and then passes request to a service object. The proxy object has the same interface as a service, which makes it interchangeable with a real object when passed to a client.

    Examples could be found here https://refactoring.guru/design-patterns/proxy/java/example

    Summary

    To sum up, adapter design pattern invloves multiple different objects to work with each other. Decorator is mainly to wrap up one object and change the inputs and outputs before or after calling the methods of the object. Proxy design pattern acts like a real proxy of an actual service to clients, it will control the acces to the service object or return cached data for the real service.

  • 相关阅读:
    Interface Builder: What are the UIView's Layout iOS 6/7 Deltas for?
    关于自定义 UITableViewCell
    关于自定义 UITableViewCell
    UITableViewHeaderFooterView can't change custom background when loading from nib
    UITableViewHeaderFooterView can't change custom background when loading from nib
    xcode制作越狱后ipa安装文件
    xcode制作越狱后ipa安装文件
    supports-screensandroid
    Windows 08 R2_组策略
    Windows 08 R2_创建AD DS域服务(图文详解)
  • 原文地址:https://www.cnblogs.com/codingforum/p/10347224.html
Copyright © 2011-2022 走看看