What is an adapter design pattern and what does an adapter pattern mean

Updated on number 2024-03-05
8 answers
  1. Anonymous users2024-02-06

    The adapter pattern transforms the interface of one class into another interface that the client expects, so that two classes that would otherwise not work together due to interface mismatch can work together. Also known as converter mode, transformer mode, wrapper mode (wrapping some existing classes so that they can have an interface that meets the needs).

    There are two adapter modes:

    1) Object Adapter Pattern - In this adapter pattern, the adapter holds an instance of the class it wraps. In this case, the adapter calls the physical entity of the wrapped object.

    2) Class Adapter Pattern - In this adapter pattern, the adapter inherits from the class that has been implemented.

    Regardless of the adapter, the purpose is to retain the services provided by the existing class and provide the customer with an interface that meets the customer's expectations. That is, on the basis of not changing the original system, new interface services are provided.

    I recommend you an authoritative book on design patterns: "Software Secrets - Design Patterns" edited by Zheng Archie. The explanation is in place, the examples are easy to understand, and I have gained a lot from reading it!

    Good luck learning the design pattern soon!

  2. Anonymous users2024-02-05

    There is already a class that implements the function, but the interface abstraction is different, so to implement an adapter pattern to match, you can see "Rambling Design Pattern", there is an electronic version. They are all a type of wrapper pattern.

  3. Anonymous users2024-02-04

    Adapter mode: Converts one interface to another interface of the client, so that the two categories that were originally non-combustible due to the non-combustible capacity of the interface can work together with each other.

    It mainly plays the role of a skin-turning rejuvenator, and the purpose is to reuse the original function.

    It is also known as converter mode, transformer mode, packaging mode; The packaging mode is to wrap some existing classes so that they can have interfaces to meet their needs.

    The role of adapters is very common in life, such as pipe adapters, three-phase socket socket converters, etc.

    There are two adapter modes:

    1. Object adapter mode:

    In this adapter pattern, the adapter holds an instance of the class it wraps; In this case, the adapter calls the physical entity of the wrapped object.

    2. Class adapter mode: In this adapter mode, the adapter inherits from the class that has been implemented quietly.

    Regardless of the adapter, the goal is to retain the services provided by the existing class and provide the customer with an interface that meets the customer's expectations. That is, on the basis of not changing the original system, new interface services are provided.

  4. Anonymous users2024-02-03

    There are two types of adapter modes:

    Object adapter mode.

    In this adapter pattern, the adapter holds an instance of the class it wraps; In this case, the adapter calls the physical entity of the wrapped object.

    Class adapter mode.

    In this adapter pattern, the adapter inherits from the class that has been implemented (typically multiple inheritance).

    Explanation: Convert the interface of one class to another interface that the customer wants. The adapter pattern allows classes that would otherwise not work together due to interface incompatibilities to work together.

    Basic Concepts Customer: The object that needs to be called by our **.

    The purpose of the adapter pattern is to retain the services provided by the existing class and provide the interface to the customer to meet the customer's expectations.

    Main content 1) Class adapter:

    When a customer defines the desired behavior in an interface, we can apply the adapter pattern, provide a class that implements the interface, and extend the existing classes to adapt by creating subclasses.

    Here's a UML diagram of a class adapter:

    2) Object Adapter:

    Object adapters" through the combination, in addition to meeting the "user expectation, interface", also reduce the poor coupling between **. Object Adaptation is recommended for work. Here's a UML diagram of an object adapter:

    3) Default adapter mode

    The default adapter pattern is a very simple adapter pattern, but this adapter is implemented by an abstract class, and all the methods specified in the target interface are implemented in the abstract class, but many of the methods are "mediocre" implementations, that is, they are all null methods. Concrete subclasses inherit from this abstract class.

  5. Anonymous users2024-02-02

    Because there are too many types of electronic devices, it is not possible to choose the power adapter to charge directly, and before choosing the power adapter to charge, you need to determine the adaptation conditions of the adapter and the electronic product.

    1. Whether the interface of the power adapter is fully matched with the device;

    2. The output voltage must be the same as the rated input voltage of the load (mobile equipment), or within the voltage range that the load (mobile equipment) can bear, otherwise, the load (mobile equipment) may be burned;

    3. The output current of the power adapter should be equal to or greater than the load (mobile device) current to provide sufficient power;

    The following is an analysis of the above three adaptation conditions.

    Clause. 1. Do not plug in mismatched interfaces without professional knowledge, otherwise it will be dangerous.

    Clause. Second, as for why the voltage needs to be consistent, in principle, it is such a lack of voltage, lack to drive the load, the battery can not be charged normally, the popular point is that the supply exceeds demand.

    Clause. Third, for why such a current configuration is needed, this involves the principle of the circuit, we all know that the power supply has internal resistance, and the larger the internal resistance, the greater the loss. Therefore, when the power adapter manufacturer produces this adapter, it will determine that the no-load output voltage is within a certain range according to the size of the internal resistance, and the current critical value corresponding to the voltage critical value is the current nominal value that I see, and the larger the current nominal value, the better the load capacity of the adapter.

    Therefore, choosing an adapter with a slightly higher current will not only not hurt the battery, but will make the charging faster.

  6. Anonymous users2024-02-01

    Here's what my blog summarized earlier:

    proxy, mode: Provides a way for other objects to control access to this object.

  7. Anonymous users2024-01-31

    Prerequisites for use:

    1 The interface specifies all the methods to be implemented.

    2 However, a specific class that implements this interface uses only a few of these methods, and none of the others are useful. 1. Implement an existing interface with an abstract class and implement all the methods specified in the interface, which can be "mediocre" implementations --- empty methods; However, the methods in this class are concrete methods, not abstract methods, otherwise all methods would still have to be implemented in concrete subclasses, which would lose the original purpose of adapters.

    2 The subclass of the interface should only be implemented in 1, and only the methods it is interested in will be implemented in its internal implementation. 1 A class that acts as an adapter is an abstract class that implements an existing interface.

    2 Why use abstract classes:

    This class is not to be instantiated. Acting only as an adapter provides a common interface for its subclasses, but its subclasses can focus only on what they are interested in. How do you make sure that a class is not instantiated or easily instantiated?

    1. Define a class as an abstract class;

    2. Set the constructor of a class to private, so that the client cannot easily instantiate a class by the new classname() method, and to generate an instance of this class, it must go through a special method, so that in a system, the use of this class can be reasonably controlled (e.g., singleton mode, multi-instance pattern, simple factory method, etc.).

    3.For two independent systems, the adapter mode has certain limitations to satisfy the OCP principle. ps:

    Video card, also known as video adapter.

  8. Anonymous users2024-01-30

    In computer programming, the adapter pattern (sometimes referred to as a wrapper or wrapper) adapts a class of interfaces to the desired cavity. An adaptation allows classes that would normally not work together because the interface is not compatible by wrapping the class's own Changcong interface in an existing class.

Related questions
3 answers2024-03-05

Adapter. Any hardware device that can communicate between physically disparate systems. The term often refers to a peripheral card inserted into a computer that provides an interface from the computer bus to another medium, such as a hard disk or network. >>>More

5 answers2024-03-05

I don't want to explain it to you at length.

To put it simply. The SCSI adapter is used to connect SCSI equipment. It is an interface card, which was plugged into the PCI interface in the early days, and now uses PCI-E or PCI-X, which is generally used in servers or workstations and home PCs >>>More

4 answers2024-03-05

1. You can use the driver disc you brought when you purchased the machine to install the complete driver. >>>More

12 answers2024-03-05

Of course you can use:

First of all: I'm going to use that first. >>>More

6 answers2024-03-05

As for the design pattern, simply put, it is a kind of architecture for the structure of the entire system when developing a large system, such as module division, hierarchy, etc., which is a high-level topic, which is done by software architects, and will not be understood without certain development experience.