I work with several data objects that can be created, read, updated and deleted, and I find that I am writing more or less the same code for them. For example, I sometimes have to output data as JSON, and sometimes in the form of a table. I find that I am writing 2 different types of views for exporting data. In addition, the creation of these objects in the database usually differs only in SQL statements and input parameters.
I am thinking of creating a strategy template to represent different "contexts". For example, the read () method for an AJAX context will return data as JSON. However, I wonder if others have problems with this problem beforehand and would like to know which design patterns are commonly used for CRUD operations.
Edit: one note is that sometimes composite objects are used to create one whole; for example, a location can have many descriptions, one for each supported language.
source share