Home> Common Problem> body text

What are the applicable scenarios for the adapter pattern?

藏色散人
Release: 2020-07-01 10:27:10
Original
7044 people have browsed it

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 visitPHP 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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!