Home > News > Products News >

Design patterns for switching power adapters

News Group
Design patterns for switching power adapters
Issue Time:2020-04-16

Switching power Adapter Pattern is the transformation of the interface of a class into another interface representation that the client expects, primarily for compatibility, so that two classes that would otherwise not work together because of interface mismatches can work together. It is alias Wrapper and is a structural pattern.

It is mainly divided into three types: class adapter pattern, object adapter pattern and interface adapter pattern. Let's go into more detail.

1. Class adapter pattern

Basic principle: Adapter class realizes DST class interface by inheriting SRC class, and completes the adaptation of src-> DST. Take mobile phone charger for example, the charger itself is equivalent to Adapter, 220V ac is equivalent to SRC (that is, the Adapter), our purpose DST is 5V dc. The class Adapter needs to inherit from the SRC class, and the DST must be an interface, so the methods of the SRC class will be exposed in the Adapter with certain limitations, increasing the cost of use. But because it inherits the SRC class, you can override the methods of the SRC class as required, making the Adapter more flexible.

2. Object adapter pattern

The basic idea is the same as the class Adapter pattern, except that the Adapter class is modified, and instead of inheriting the SRC class, it holds an instance of the SRC class to solve the compatibility problem. In other words, use association relationships instead of inheritance relationships in Adapter classes. Again, the class diagram looks like this: object adapters and class adapters are really the same idea, but implemented differently. According to the principle of composite reuse, using composite instead of inheritance solves the limitation that the class adapter must inherit SRC and no longer requires that DST must be an interface.

3. Interface adapter mode

Also known as Default Adapter Pattern, its core idea is that when all the methods provided by the interface are not needed to be implemented, an abstract class can be designed to implement the interface, and provide a Default method for each method in the interface, then the subclass of the abstract class can optionally override some methods of the parent class to implement the requirements. This is mostly true when an interface doesn't want to use all of its methods.

4, summarize

Three naming methods of adapters are based on how SRC is given to Adapter, that is: class Adapter: to give a class to Adapter, is to treat SRC as a class, through inheritance; Object adapter: given as an object, SRC as an object, by holding; Interface adapter: to interface to, SRC as an interface, through the implementation to complete; In short, the biggest role of the adapter pattern is to integrate originally incompatible interfaces and work together. In the actual development, the implementation form should be used flexibly and not be restricted to these three forms.

Switching power supply Related articles:

How should the switching power adapter be used?

What are the models of medical switching power adapter?

What are the switching power adapter used in industry?

What are the advantages of high frequency switching power adapters?

What are the good switching power adapter manufacturers? How many switchingpower adapters are there

Get in Touch

Quick Service & Solution For Full Meanwell Products

If you have any questions about purchasing Meanwell products, any doubts in product selection, or any special needs for Meanwell products, welcome contact us as follows:

Stay in touch
Please send your message to us

Agree to use terms of service