Design Patterns. Should updating and removing factory?

I am busy with design. I use factory to get data from a database, create an object and return it. But what design patterns can I use when I want to update or delete data in a database? Can a factory update and delete or create another design pattern for this? An example in Java or PHP would be nice.

Thanks for your support!

+4
source share
1 answer

No, not at all. Factories build things, that's all. In cases where the ActiveRecord template is used, objects have a save method. Using ORMs such as Hibernate, a session stores objects.

Java , SessionFactory ( EntityManagerFactory), Hibernate ( EntityManagers), Hibernate , , - . , session.save( Hibernate , , ), :

EntityManager manager = entityManagerFactory.create();
MyEntity entity = manager.findById(someid);
entity.setName("new name");
manager.save(entity);
+3

Source: https://habr.com/ru/post/1541628/


All Articles