jeudi 20 juillet 2017

Should I use factory to update object?

I use factory to create entity by command object, but when I want to update entity from command object, I can't find a good patten to do this. Should I just use factory to update entity, or if not, what is a good pattern?

interface ProductFactory {

    Product create(ProductCommand command);
    Product update(Product product, ProductCommand command);
}

my service:

class ProductServiceImpl {

     public Product updateProduct(long productId, ProductCommand command) {
         Product product = productRepository.findOne(productId);
         product = productFactory.update(product, productCommand);

         return productRepository.save(product);
     }
}

Aucun commentaire:

Enregistrer un commentaire