Design Patterns: Should a factory update and delete too?
database, design-patterns, object, oop
Solution
No, not really. Factories build things, and that's all. In cases where the ActiveRecord pattern is used then entities have a save method. With ORMs like Hibernate the session persists entities.
In Java what happens is you have a SessionFactory (or EntityManagerFactory), that creates Hibernate Sessions (or EntityManagers), and a Hibernate Session has methods like save that take an object and persist it or do whatever with it. The entity object would get updated with new values and then it would be passed as an argument in a call to session.save (though in many cases Hibernate can figure out what changed, so no explicit call to save is required), like this:
EntityManager manager = entityManagerFactory.create();
MyEntity entity = manager.findById(someid);
entity.setName("new name");
manager.save(entity);
Problem
I am currently learning about design patterns. I use a factory to get data from a database, create an object, and return that. But what kind of design patterns can I use when I want to update or delete the data in the database? Can the factory do an update and delete too, or exists another design pattern for that? An example in Java or PHP would be helpful. Thanks for your support!