Pregunta

I have recently seen an EJB code with a Facade pattern to provide some methods to be used in presentation layer (JSF). But in some part of the business logic, the methods of the Facade is called and have been used.

That seems a little strange to me since I think the Facade is supposed to serve the outer world not the internal functionality. Am I right or I got paranoid?

This is a rough (stupid) diagram to illustrate the situation:

Facade

¿Fue útil?

Solución 2

No, you shouldn't in my opinion. The façade is there to regulate the interface between layers; it shouldn't be used from inside the layer as well.

And it shouldn't be necessary either. I'm assuming getProductById delegates the call to some sort of repository which fetches the Product. You can use dependency injection to inject your repository in the appropriate classes. In the small UML sample I drew up just now (it's been a while, forgive me if some connections aren't correct) I demonstrate this approach.

enter image description here

Now the Report class has access to the ProductRepository and can fetch the data from there instead of going through the Façade class.

Otros consejos

Yes, you are right! Facade provides an interface of something complex, by hiding the complexity and haphazardness to its client. The client can be JSF view page, another bean or service. There is no technical problem as long as you are using it accordingly!

But generally, if you have done layering in conventional manners, it should not be like what you described.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top