"Design Mode Design Pattern" reading notes six

xiaoxiao2021-03-06  14

Adapter mode

Alias

Wrapper

structure

Class Adapter

Object Adapter

purpose

1. We need to use an existing external class, but the interface of this class is inconsistent with our existing system.

2, or we want to create a class that can be used flexibly, we can first design this class very detailed, then design one or more simple "pluggable adapter", these simple " The interface of Pluggable Adapter is very simple and can be easily cropped in different use environments.

Excellent and disadvantages of Class Adapter and Object Adapter

1. Generally, Object Adapter is more flexible, and you can avoid multiple inheritance. Therefore, it is recommended to use Object Adapter in most cases.

2. Class Adapter can create a Two-Way Adapter. Two-Way Adapter can be used any environment that Adaptee can be used.

Reference

"Design Pattern" Gang-Of-4 1997

转载请注明原文地址:https://www.9cbs.com/read-47036.html

New Post(0)