Home  >  Article  >  What are the applicable scenarios for the adapter pattern?

What are the applicable scenarios for the adapter pattern?

藏色散人
藏色散人Original
2020-07-01 10:27:107115browse

Applicable scenarios for the adapter pattern include: 1. You want to use an existing class, but its interface does not meet your needs; 2. You want to create a class that can be reused, and the class can be changed with Other unrelated classes or unforeseen classes work together; 3. You want to use some existing subclasses, but it is impossible to subclass each one to match their interface.

What are the applicable scenarios for the adapter pattern?

Adapter pattern

Converts the interface of a class into another interface that the client wants. The Adapter pattern enables classes that would otherwise not work together due to incompatible interfaces to work together

Applicability

  • You want to use an existing class, and its interface does not meet your needs

  • You want to create a reusable class, and the modified class can be compatible with other unrelated classes or unforeseen (may be incompatible ) classes work together

  • You want to use some existing subclasses, but it's not possible to subclass each one to match their interface

For more related knowledge, please visit PHP Chinese website!

The above is the detailed content of What are the applicable scenarios for the adapter pattern?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn