码迷,mamicode.com
首页 > 其他好文 > 详细

适配器模式 vs 装饰者模式

时间:2019-02-01 23:01:10      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:spec   and   let   java   ural   cin   cal   factor   ada   

Reference

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

1. Adaptor 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.

Exampes 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.

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

适配器模式 vs 装饰者模式

标签:spec   and   let   java   ural   cin   cal   factor   ada   

原文地址:https://www.cnblogs.com/codingforum/p/10347224.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!