How to implement a pluggable Adapter design pattern in Java?
How to implement a pluggable Adapter design pattern in Java?
Let’s say we have a client class called Client.java which calls method1( ) of an existing library class LibM to fulfill a functionality.
Let’s say we need the client class Client.java to be able to accomplish the same functionality (printing a message) using another library class LibN. However, the new library class does not have a method named method1( ) but instead has methodA( ) for the same functionality.
In order to use the new library class we need to build an adapter class and an adapter interface as follows. Use of the interface class allows plug and play capability. We can interchange the concrte library implementation class without having to make extensive changes to the client class. Also, in future if new library classes need to be used we need to build new adapter classes implementing the same library interface class.
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 5 images