I have been referred to the facade design pattern in web a lot. Literally it is clear to imagine what a facade bean is. When it comes to implementation though, I am unable to make any difference from delegate pattern. Can any one explain the implementation of the facade pattern and how it differs from the delegate pattern in Java?
-
http://en.wikipedia.org/wiki/Facade_pattern#Example – Christophe Roussy Mar 01 '13 at 11:20
-
try here: http://sourcemaking.com/design_patterns/facade/java/1 – konradstrack Mar 01 '13 at 11:22
-
http://zuta-developer.blogspot.com/2012/06/facade-pattern.html#.UTCPXOu1ejU – Andreas Dolk Mar 01 '13 at 11:22
2 Answers
Facade pattern provides you with an abstraction layer that hides all the implementation details. Delegation is the ability of having other entity doing your work, you delegate.
In Java you can create a Facade class, and inside use a collection of classes that have the real code. For Delegation you receive, for instance in the constructor, a reference for other class, then you call some predefined API in the second class, since the delegated probably implements some kind of interface.

- 2,077
- 4
- 21
- 45
A Service Facade is usually the entrance point for clients. It provides a coarse grained, use case driven API. A Service Facade starts the transaction, converts from/ to DTOs if necessary and can call fine grained Services and DAOs.
For Web application there is also the Gateway pattern (stateful EJB with an extended persistence context) which can be used instead of a Service Facade in some situations. (JPA Entities don't get detached.)
For more information have a look at the book "Real World Java EE Patterns - Rethinking Best Practices", by Adam Bien: http://realworldpatterns.com/

- 37,247
- 13
- 80
- 152