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.

Both the adapters implement the Lib_Interface interface which has a method called method1( ). Hence the client class which will use the library concrete implementations will be aware of only the method in the contract Lib_Interface. In the method implementations of the adapter classes the method call to the actual library class is made. In other words, the adapters delegate the method call made by the client to the concrete library class method each of them embed.

The implementation demonstrates the pluggability of the adapter approach. The concrete library class to be instantiated and used is known only at runtime. It is passed as an argument at the command line while running the client class. Inside the client class both the library concrete instances are of type Lib_Interface so that run time dynamic binding can be accomplished and the method1( ) can be called on both the concrete implementations. After compiling the classes and the interface, the code is run by as follows at the command line:
>java Client “M”
>java Client “N”
In each case the appropriate library class is called and the message is displayed accordingly.

Ask a Homework Question!


Related Computer Science Q&A
Find answers to questions asked by students like you.
Q: Compare the type error detection for instance variables in Java andRuby.
A: Answer is given below .
Q: State the Mangling of linker symbols in C++ and Java ?
A: Both C++ and Java permit over-burden techniques that have a similar name in the source code however…
Q: What is HDL? Is there any difference between HDL and Java?
A: Click to see the answer
Q: How to make log-in program in java using GUI
A: The below-given java program will obey the following rubrics: Importing required packages.…
Q: What is meant and what is the function of the Marker Edge Colo command in Matlab
A: M = mean( A ) returns the mean of the components of An along the main exhibit aspect whose size…
Q: Design such an interface using java fx
A: <?xml version="1.0" encoding="UTF-8"?> <?import javafx.scene.control.Button?><?import…
Q: Give examples of the two approaches to implementing the abstract methods defined in the JavaRMI…
A: All methods in an interface are defined with an empty body and are public by default, and all fields…
Q: Explain synchronization in Java with a suitable example.
A: Synchronization in java definition: The process of allowing only one thread at a time to complete…
Q: I want GUI for ATM "java -oop" simple design no problem ... Thanks
A: The project contains three .java files.The main file is mainpageATM.java mainpageATM.java /* *…
Q: Explain the Differentiate between for and for…in, In relation to JavaScript
A: The answer is..
Q: crreate a java code using the premutations method
A: as per the question statement, We need to write java code for permutation.
Q: gramming
A: How is Lambda useful By specifying an anonymous function that may be provided as an argument to some…
Q: What are the pros and cons of using R-interface ? Computer science
A: Pros of R-interface: R is a free and open-source programming language. R enables users to…
Q: Define "linker" in a few words.
A: The process of creating a program that changes two or more machine-language program segments for…
Q: Mention the two ways of implementing the abstract methods declared in the interface when developing…
A: Abstract classes are similar to interfaces. You cannot instantiate them, and they may contain a mix…
Q: What is the interface design of tiktok including good and bad interface?
A: The answer is given below:-
Q: What do you mean by encapsulation in cloud computing?
A: Answer is in step 2
Q: Explain about Java package ( Swing. awt. event ) with example for each?
A: Java Swing is a widget toolkit for creating a graphical user interface (GUI) in Java that contains a…
Q: Writing a Modular Program in Java
A: Lets see the solution in the next steps
Q: How to implement double buffering in java game development?
A: Double-buffering is the process of drawing graphics into an off-screen image buffer and then copying…
Q: What’s the usage of callback interfaces in hibernate?
A: Callback interfaces are used in the application to receive notification when certain object event…
Q: Name the two data types available in Verilog and distinguish the difference between them.
A: Verilog is the datatypes are the data storage and transmission elements found in digital hardware…
Q: In java, how we can disallow serialization of variables?
A: If the object must be serialized, apply the nonserialized attribute to specific fields that store…
Q: thods an inte
A: outline three diffrent methods an interface body can contain in java
Q: Write an introduction or a summary with sources on the use of computer graphics in the field of…
A: OpenGL is a software interface that permits the programmer to make 2D and 3D graphics pictures.…
Q: What are the methods of JLable class in Java Swing?
A: We have to define the methods of Jlable class in Java Swing.
Q: Explain shutdown method in ExecutorService of Java.
A: Step 1 The Java ExecutorService is the interface which permits us to perform jobs on threads…
Q: Would someone mind helping me with doing a series of UML Sequence Diagrams detailing how the rest…
A: UML Sequence Diagram UML sequence diagram describes how operations are carried out and what will be…
Q: Computer Science Django python check for authentication for each api end point. - django tokens -…
A: Solution: Token Authentication This authentication scheme uses a simple token-based HTTP…
Q: crreate a java code using the combination method
A: import java.util.*; public class comb { static int factorial(int nn) { int x = 1,k=1;…
Q: i want from you to Investigate how we can create a tool to extract the UML automatically from a…
A: Lets see the solution in the next steps
Q: Java multi-threaded programming
A: Introduction Thread is basically a type of execution and a process that provides an operation, in…
Q: Write the syntax of synchronus fetch api in JavaScript. Solve correct answer only.
A: According to the given question, it is required to write the syntax of synchronus fetch api in…
Q: What are the pros and cons of using R-interface over RStudio interface?
A: R is a software framework for breaking down factual information and graphical portrayals.…
Q: Q: Outline a simple protocol that implements at-most-once semantics for an object invocation.
A: At-most-once semantics is one of the standard models for object access in decentralized frameworks.…
Q: , Examine user-interface components with titles, buttons, and text content.
A: Examine user-interface components with titles, buttons, and text content.
Q: django python Create test cases for the api's functionality.
A: Here i write the code for test cases in dijango python:…
Q: Rewrite this java method in SWIFT and GO languages
A: Given: Rewrite this java method in SWIFT and GO languages
Q: Briefly describe three different implementation strategies for a symbolic debugger.
A: Given: Three different implementation strategies for a symbolic debugger.
Q: How do I implement a factory pattern and creational pattern in java ? Illustrate with an example
A: The creational pattern is a technique of design in coding that allows the runtime initialization of…
Q: What is a wrapper class in Java?
A: What are Wrapper classes in java? A Wrapper class is a class whose object wraps or contains…
Q: How to envoke multiple simulators in Xcode?
A: Xcode does support multiple simulator build and debug. The steps to be followed to envoke multiple…
Q: implement complete linkage clustering in jupyter notebook (Python).
A: Step 1: Use sci-kit learn library for the clustering algorithms. use the cluster.dendrogram module…
Q: How to scale a polygon in java?
A: import java.lang.*; import java.util.*; import java.util.List; import java.io.*; import java.awt.*;…
Q: What is a servlet, and how does it work? Describe the servlet lifecycle and the…
A: Servlets are programs in java which runs on java enables web server or application server. Its main…
Q: make a checkered board in javafx
A: The answer is given below.
Q: Create a UML design (based on java) to make changes/edit VM's that are already on the network.
A: Uml diagram
Q: Explain any two ServerSocket methods used in java?
A: Hello Student. Warm welcome from my side. Hope you are doing great. I will try my best to answer…











