Introduction to adapter pattern of Java design pattern

This paper illustrates two adapter modes, class adaptation mode and object adaptation mode, as follows:

1. Class adaptation mode:

Take an example: in the earth era, all mounts can only run and can't fly, but now many mounts can fly on the earth. Assuming that the mount in the earth era can only run, and the current mount can not only fly but also run, we can use the class adaptation mode to realize it. It should be noted here that the adapter inherits the source class and implements the target interface. The example code is as follows:

2. Object adaptation mode:

Suppose an adapter wants to adapt to multiple objects, you can introduce these objects into the adapter, and then call the methods of these objects.

The implementation code is as follows:

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>