In the adapter modeProgramThe design interface is converted into another interface. When we want unrelated classes to work together in a program, we can use the adapter mode. The concept of an adapter is quite simple: compile a class with the required interface, and then let it communicate with the class with different interfaces.
Class adapter: derives a new class from an inconsistent class, and then adds the required method so that the new derived class can match the required interface.
Object Adapter: contains the original class in the new class, and then creates a method in the new class to convert the call.
Understanding: In the adapter mode, you can include controls in the adapter class in actual applications and then call them directly.
Differences between class adapters and object adapters:
1When we want to match a class and all its subclasses, the class adapter will not be competent, because the base class derived from the subclass has been defined at the time of creating the subclass.
2The class adapter allows the adapter to change methods of some matched classes, and also allows other unmodified methods.
3The Object Adapter allows all child classes to be matched by passing subclass to the constructor.
4The Object Adapter requires the reader to put the method of matching the object to the surface.