Domanda

Before I ask my question I must describe how our applications are built.

We run several web applications that uses ejb´s in the service layer. I try to describe the communication with a short example:

  • A JSF bean (PersonHandler) calls a facade to delete a "Person" object
  • A Facade can use many different services but CANNOT use other facades. In this case the PersonFacade uses a PersonService (to delete the person) and a NotificationService (to send an email). Also transactions are controlled by the facade logic. Emails should only be send if the transaction is successfully committed.
  • A Service CANNOT have a reference to another service or facade. Instead of this the PersonService has only a reference to the PersonDao (persist logic).

I think this architecture is quite common. Here´s my question.

In the PersonFacade´s delete method we have really important code that we won´t duplicate. Every time a person should be deleted this piece of code should run. In another facade logic we need exactly the same code but facade <--> facade communication is not allowed.

What is the best solution for this problem?

Heres my current solution but I´m not happy with it. I created a new ejb module with an ejb that handles the delete logic. Both facade modules has dependencies to the new module so everything works find and I don´t break the "facades never use other facades" contract. If we use this everytime we need the same code at different places our modules will explode and the modules will become confusing. At the moment we have more than 250 ejb/jar modules.

È stato utile?

Soluzione

Below are two options that i would consider.

  1. Have the common logic in a base facade that all facade's will extend from, or
  2. Move common logic to an helper class (utility) that any facade can invoke. I see you are already doing a similar thing by creating a new ejb. I am not sure if it needs to be an ejb, depends on the exact logic.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top