Adapter Pattern in Java

As the name suggests, adapting the current class to work with another class. This is what an adapter does.

Use Case:

Doing a data analysis on X-Ray data.

Say, you are building a health care software. You get data from different type of X-Ray Machine(ie different manufactures). Your program is supposed to do Data Analysis on Health Care Machine data.You software is programmed to work on Cisco X-Ray Machine. But, at later point of time, you need the software to adapt to IBM X-Ray Machine. What should you do?

You create a interface(Literal meaning) to handle the data conversion, data retrieval etc, so that software can interact with IBM X-Ray Machine in a standard way. You are creating a Global Template and then creating interfaces(Literal meaning) for different manufacturers of X-Ray Machine.

2. Analog to Digital:


Say we have an analog sensor, which outputs analog signals. But our program can only interact with digital signals. Hence we create an adapter (AnalogToDigital ) to convert analog to digital.

3. Apple created a whole system of Adapters, to make it work on Intel Processors.

X-Ray machine Example

In the end, every manufacture data set will be likely of the same format, but there might some variations in terms of unit of measurement (Kg/Pound or °F /°C ) etc. So we need to standardize this values, so that our program can expect the same kind of data set from all the manufactures.

Project Structure:

Implementation in Java

2. Let create a standard template for X-Ray machine.

Concretion Adapter for the above Interface.

3. Driver class to test this.

Found it Interesting?
Please show your support by 👏. To read the complete series, click below.

I myself, has just started learning, design patterns. If you find any issues please feel free to post them in the comments section below. Thank you for reading so far 😄

Writes on Big Data, AWS & Backend technologies.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store