Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Under what circumstances do you use Adapter mode

Shulou Source: shulou.com Published: 2022-06-01 03:35:41 10月27日 Update

This article focuses on "when to use Adapter mode", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "under what circumstances to use Adapter mode"!

Applicability

Adapter mode is used in the following situations

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

This is the example described at the beginning of the adapter pattern. We can use the adapter pattern when we want to use an existing class, but we don't want (and should not) modify the interface of that class.

This is a passive adaptation.

You want to create a reusable class that works with other unrelated or unforeseen classes (that is, classes whose interfaces may not be compatible).

Imagine that we are developing some reusable function, and of course we want it to have an ideal, beautiful interface. But the interface required by the system developed at the same time may be that beautiful. What we should do at this time is not to compromise and make do, but to use the adapter pattern to isolate the two. This is an active adaptation.

(object Adapter only) you want to use some existing subclasses, but it's not possible to subclass each to match their interface. The object adapter can adapt to its parent interface.

When we want to adapt a group of classes, we can let the adapter keep the pointer of the object parent class type, which is as long as the parent class interface is adapted, then we will naturally complete the adaptation of all subclasses.

At this point, I believe you have a deeper understanding of "under what circumstances to use Adapter mode", you might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Adaptations interfaces patterns situations adapters subclasses objects beauty content reuse learning development practicality deeper initiative examples interests functions and at the same time practicality Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple MySQL NVidia Shulou Tech Info macOS