Umesh Awasthi Umesh Awasthi - 1 month ago 10
Java Question

Use of Facade pattern

While developing a web based java application I am a bit confused about the use of Facade pattern or, more precisely, can say that I am not able to visualize its exact use.
Here is my use-case:

I Have a web-application where I have Action classes, Service layer and DAO layer as well. My Action classes are responsible to interacting with the UI (JSP) while the service layer will be responsible for handling any business logic as well interacting with the DAO layer and getting DB related work done.

I can create service layer interface and can expose them in my action classes so as my action classes can interact with the Service layer and do any work.

I was asked to introduce another layer as Facade where I am required to expose methods to my Action class while the service layer is now being exposed in the Facade.

Can any one help me to clarify what is being asked is correct and what benefits will be achieved by this approach as it seems to me like introducing additional layer with no much work being done in facade layer (heavy lifting still be in service layer.)

Tom Tom
Answer

by using a facade in between your services and your actions, you not always have to use particular services in your actions, you just use the facade. Also, some actions will use combinations of services in the same way, if you can put this in a method in your facade, you'll save yourself some time cause you can just reuse a facade method that uses that combination of services.

Comments