My doubt is quite simple. Recently I have started to use the Facade Pattern, but I don't know if I fully understand the concept behind it. To make this simple, I'm coding from the standard proposed by NetBeans for RESTful web services:
public abstract class AbstractFacade<T> {
private Class<T> entityClass;
public AbstractFacade(Class<T> entityClass) {
this.entityClass = entityClass;
}
protected abstract EntityManager getEntityManager();
public void create(T entity) {
getEntityManager().persist(entity);
}
public void edit(T entity) {
getEntityManager().merge(entity);
}
...
}
Then, I have my entity classes and my "MyClassFacadeREST" files with the usual methods (GET, PUT, etc.) which, from the beginning, call to the parent methods (for instance, POST method in MyClassFacadeREST calls to the super.create(entity) in the AbstractFacade):
@Stateless
@Path("entities.[...]")
public class MyClassFacadeREST extends AbstractFacade<EntityClass> {
@PersistenceContext(unitName = "[...]PU")
private EntityManager em;
public MyClassFacadeREST() {
super(MyClass.class);
}
@POST
@Override
@Consumes(MediaType.APPLICATION_JSON)
public void create(EntityClass entity) {
super.create(entity);
}
...
}
My doubt is that I'm not sure where it is more correct to customize these methods for each entity class. I mean, if I want to perform some kind of operations before a POST command, for example, for a particular entity class, it would be more correct to create this custom POST in the general AbstractFacade class or in the MyClassFacadeREST class?
Considering the concept of keeping the particular details simple, I'm not sure if it is better to maintain the super.[...] calls structure in MyClassFacadeREST classes and write a bunch of heterogeneous methods in the AbstractFacade or keep the AbstractFacade as general as posible and write the details in each MyClassFacadeREST class.
Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire