Should you separate model functions, even if they retrieve the fields of data?
Lets say I have an Articles Model that gets Articles from the database.
I have a function, getUserArticles($id), that gets the users articles. I have a function, getAllArticles($offset, $limit), that gets a list of articles.
Should I leave the two functions separate from one another, or combine them somehow.
The reason I ask is because if I were to alter, add, or remove a field from the query, I would have to do the change in every function. So if I change my mind and decide I no longer want to show the time_added for every article, I would have to remove it from every function.
It is better to expose two distinct functions to the user of the API but internally you can use the same code for both if you believe that there will be better code reuse that way.
For example: you will define a generic getArticles (used internally only)
then you define your exposed functions like this
NOTE: only do this if you believe there is common code between the two functions. If there is no common code then keep them separate and there is no need for the generic getArticles function which I suggested.
I don’t know if the above is valid php code but I think the idea is clear.