Adapter , Adapter , Adapter ~ Actually Adapter design pattern can consider as a simple conversion program / class. It usually used to make two incompatible interfaces or classes to work together.

Case Study
Company A developed a program in Java to display all of the products’ detail in console. This Java program is very simple and it take an Iterator collection and iterate it to display product one by one.
However Company A outsource Product back end system to a vendor called Vendor B. Vendor B came out a system which will return all products as Enumeration collection.
Arg…wait… return Product as Enumeration? But current Company A system is design to accept product as Iterator. Company A design are all base on Iterator collection to function, now Vendor B provide an old and obsolete function (Enumeration), what should we do?
Above scenarios sound similar to everyone right? Yes it always happened to me as well. So .. who going to change it? To be frankly, i can guarantee Vendor B 100% will not change it for you.
However company A also can not afford to redesign it because it invested so much time and manpower effort already.
Here Adapter come in place. What we need to do is create an adapter class which can convert Enumeration to Iterator. Understand? Study below code may make sense to you.
Code Study
This is an “EnumProduct” class provided by vendor, it will return Product as Enumeration by calling getProduct () function.
1 | package com.mycompany.adapter; |
Here is Company A “Product” program which is use to display all products on console screen.
1 | package com.mycompany.adapter; |
Company A use displayProduct(Iterator iterator) function to display all of the products information in console. Company A do not want to change and insist want accept Iterator as parameter.
Here Adapter Design Pattern can make it work without any changes involve in current system and vendor’s class as well, what Company A need to do is create an Adapter class to convert Enumeration to Iterator like below
1 | package com.mycompany.adapter; |
Ok, now revisit Company A “Product” class, it can accept Enumeration now!!!
1 | package com.mycompany.adapter; |
We didn’t changed anything in either Product Class nor EnumProduct class. We just create a new Adapter class to convert Enumration to Iterator class. Done.