As the name suggests, adapting the current class to work with another class. This is what an adapter does.
- Healthcare Machinery :
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
Since we need to perform data analysis on multiple dataset, we need adapters for various manufactures.
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.
Implementation in Java
- We have interfaces(Literal meaning) for different manufactures. They provide us with functions to collect respective data.
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 😄