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

6 Design Patterns Java Structural m6 Slides

The Facade Pattern simplifies the client interface, making APIs easier to use and reducing dependencies on external code. It is primarily a refactoring pattern that utilizes composition rather than inheritance and typically encompasses the full lifecycle of the API. Key examples include java.net.URL and javax.faces.context.FacesContext, and while it is effective in cleaning up code, careful consideration of API design is necessary.

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

6 Design Patterns Java Structural m6 Slides

The Facade Pattern simplifies the client interface, making APIs easier to use and reducing dependencies on external code. It is primarily a refactoring pattern that utilizes composition rather than inheritance and typically encompasses the full lifecycle of the API. Key examples include java.net.URL and javax.faces.context.FacesContext, and while it is effective in cleaning up code, careful consideration of API design is necessary.

Uploaded by

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

Facade Pattern

Bryan Hansen
twitter: bh5k | http://www.linkedin.com/in/hansenbryan
Concepts
▪ Make an API easier to use
▪ Reduce dependencies on outside code
▪ Simplify the interface or client usage
▪ Usually a refactoring pattern
▪ Examples:
▪ java.net.URL
▪ javax.faces.context.FacesContext
Design

Class that utilizes composition


Shouldn’t have a need for inheritance
Typically encompasses full lifecycle
UML
Everyday Example - URL
URL  url  =  new  URL("http",  "www.pluralsight.com",  80,    
"/author/bryan-­‐hansen");  

BufferedReader  in  =  new  BufferedReader(  


new  InputStreamReader(url.openStream()));  

String  inputLine;  

while  ((inputLine  =  in.readLine())  !=  null)  {  


  System.out.println(inputLine);  
}
Exercise Facade

Complex Client
Client, Facade, JDBC
Simplified Client Code
Pitfalls
▪ Typically used to clean up code
▪ Should think about API design
▪ Flat problem/structure
▪ The “Singleton” of Structural Pattern
Contrast

Facade Adapter
▪ Simplifies Interface ▪ Also a refactoring pattern
▪ Works with composites ▪ Modifies behavior (adds)
▪ Cleaner API ▪ Provides a different interface
▪ Single Object
Facade Summary

• Simplifies Client Interface


• Easy Pattern to implement
• Refactoring Pattern

You might also like