views:

83

answers:

1

Hi Guys,

I have a fully implemented DAO and all my beans inherit an Entity object. Now, I want to create a client notification system whereby, when a user creates/updates/delete an entity to/from a persistence storage, a notification is automatically sent to the client via email.

I have a DAO manager that uses a Factory Pattern to return to me a manager of the DAO based on the entity type.

e.g EntityManager manager = EntityManagerFactory.createEntityManager(Product.class);

each manager has a create(), remove(), update() method....

My first idea is to have all my entity managers inherit an Observer interface and after the function calls (create, remove, update, etc.) a notification is sent.

Is that a wise idea? If not, what can I do in order to send a notification to client?

I'm running JBoss 5 or Tomcat 6 (or both for easy deployment) and Apache Struts (though I don't see the reason why I mentioned it).

Thanks in advance.

+2  A: 

Consider using a decorator pattern to allow your entity managers to remain blissfully unaware of who needs to be notified and how to send them emails. This approach will improve maintenance of both the existing manager code and the messaging code you intend to write, and will pay off hugely if you ever need to write new entity managers what store your entities in JCR or tranmit them via web services, etc.

Drew Wills
Ok, Interesting suggestion. How would I use a decorator exactly in this scenario? I know what you're saying, but is it possible to add it without me having to change my structure already?
The Elite Gentleman
It's possible to add it without changes to existing code if you either (1) use an IoC container or (2) some flavor of factory pattern to define the EntityManager impl in use within your system.
Drew Wills