Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

Hi Pankaj, Very simple and clear example. Please provide some knowledge on test framework also like junit or testng.
- HIMANSU NAYAK
Nice One. Pretty clear cut explanation. keep it on. Thanks, Manoj@ CITE
- MANOJ @ CITE
Hy Pankaj Kumar, thanks for your post, I have a question: reading Head first Design pattern, it seem in the Adapter design pattern get involved a bit od delegation, since all the requests made from the client using target interface, will be done delegating the job to the adaptee object. Actually I can’t see this in the Arrays.asList, because after all you’re creating a new object from using this method and not adapting array to respond to List interface using an adapter. It seems for me more reasonable and Adapter compliant in this manner: //ListAdapter.java public class ListAdapter implements List{ private String[] array; public ListAdapter(String[] array) { this.array=array; } @Override public int size() { return array.length; } /*Other methods*/ } // Test.java public static void main(String[] args) { String[] array = new String[2]; array[0]=“Giorgio”; array[1]=“Sara”; /* Versione artigianale del adapter tra array e list */ List list = new ListAdapter(array); System.out.println(list.size()); }
- Giorgio
Where are your two unrelated interfaces in these examples ?
- Mahadev Shinde
Hello Pankaj, could you please show us how does Object Adapter work ? i mean as Code in Java ? best regards Raed
- Raed
Keep in mind that with class adapter, you’re extending the adaptee (Socket.java in this case), which might pollute your API with undesirable methods/members of Socket.java and all of its parents, because you’re inheriting everything from Socket.java, giving the client more code than it needs/wants. This is important to keep in mind if you’re adapting a class that you don’t own from a 3rd party or something like that. Also, because the adapter is statically linked at compile time, you cannot adapt child classes of Socket.java. Object adapter is more flexible because you can adapt not only Socket.java, but all of its child classes as well.
- Jose M Quijada
What you have explained here, to some extent looks like strategy pattern. adapter pattern must be like below DestinationInterface adapt(SourceInterface si){ DestinationInterface di = new DestinationInterface (); //logic to convert / map SourceInterface to DestinationInterface return di; }
- ravi
Hi, I love this tutorial. its really help me a lots to understanding. Thanks a lot
- Debi Boxi
Hi Pankaj, Your example was really good, it did help me understand the adapter pattern. I referenced your post while creating my demo for the same.
- Yogesh