Search code examples
javadesign-patternsdelegatesjava-ee-6facade

Facade pattern vs Delegate pattern; In Java?


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?


Solution

  • 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.