I'm doing a little bit of cleanup and I'm trying to gather all the spread SQL queries done to an object into a single place. I have a class whose responsibility is to present a CRUD interface to the developer, and to encapsulate the results coming from selection queries into objects, that at the same time can be updated or deleted.

So far so good. However, I noticed that across the site we have 115 different places where an object retrieval is done. I managed to find out that there are a total of 17 cases which, with a little bit of witchcraft and making a couple parameters optional, could be reduced to 9.

9 retrieval methods feels too much to me for a class, especially if it already has many more methods to do the CRUD.

I thought of using a mixin (more specifically in PHP, a trait) to keep all the methods together and "in the class", although separate enough, to keep the main class as clean as possible (with just the most complete retrieval method, whose all the other methods would depend on), although since mixins are used to encapsulate and reuse across many classes, I wonder if there's a better way to do this without making the class too crowded.

For the record, this class is not an ORM itself, although it uses one internally to do all the CRUD tasks. Instead, the methods are called like get_by_id, reset_timer, add_feature, and so.

1 Answer 1


I think you might be over complicating this. There is nothing wrong with creating another class just for data retrieval. The main CRUD class could delegate the query logic to the data retrieval class.

Composition is your friend.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.