0% found this document useful (0 votes)
2 views

2-design-patterns-java-structural-m2-slides

The Adapter Pattern allows for the conversion of one interface into another, facilitating integration between new and legacy systems. It is client-centric and provides a simple solution to adapt various implementations without adding new functionality. Key concepts include the roles of Client, Adapter, and Adaptee, with practical examples like converting arrays to lists.

Uploaded by

podam91581
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

2-design-patterns-java-structural-m2-slides

The Adapter Pattern allows for the conversion of one interface into another, facilitating integration between new and legacy systems. It is client-centric and provides a simple solution to adapt various implementations without adding new functionality. Key concepts include the roles of Client, Adapter, and Adaptee, with practical examples like converting arrays to lists.

Uploaded by

podam91581
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Adapter Pattern

Bryan Hansen
twitter: bh5k | http://www.linkedin.com/in/hansenbryan
Adapter
Concepts
▪ Plug adaptor
▪ Convert interface into another interface
▪ Legacy
▪ Translates requests
▪ Client, Adapter, Adaptee
▪ Examples:
▪ Arrays -> Lists
▪ Streams
Design

Client centric
Integrate new with old
Interface, but not required
Adaptee can be the implementation
Everyday Example - Arrays.asList

Integer[]  arrayOfInts  =  new  Integer[]  {  42,  43,  44  };  


     
List<Integer>  listOfInts  =  Arrays.asList(arrayOfInts);  
     
System.out.println(arrayOfInts);  
     
System.out.println(listOfInts);
Exercise Adapter

Walkthrough
Create Adapter
Decorator
Another Adapter
Pitfalls
▪ Not a lot!
▪ Don’t complicate
▪ Multiple Adapters
▪ Don’t add functionality
Contrast

Adapter Bridge
▪ Works after code is designed ▪ Designed upfront
▪ Legacy ▪ Abstraction and implementation
▪ Retrofitted vary
▪ Provides different interface ▪ Built in advance
▪ Both adapt multiple systems
Adapter Summary

• Simple solution
• Easy to implement
• Integrate with Legacy
• Can provide multiple adapters

You might also like