Adapter mode:
Adapted classes:
Adapter interface:
Adapter: Use the class adapter approach, which has a disadvantage because Java only has single inheritance,
Caller: Superclass reference to subclass object (polymorphic)
The caller invokes the adapter,
Super. Request (); Adaptee’s request() is actually called;
To access the object being adapted.
The second adaptation, object adapter, uses a composite approach to integrate with the object being adapted
Integrate the adapted object into the adapter class, through the getter(),
The setter() method calls the adapted object
Caller:
Create the adapter to introduce the adapted object A
Target t = new Adapter2(a)
Use the request() method of the adapted object directly inside the adapter.
Class diagram:
Where the adapter is used:
Two adapter modes