问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/2068425/how-to-create-a-client-notification-service-for-a-webapp-or-should-i-use-an-obse