After an unresolved argument with a friend I decided to ask the stack overflow community. Is there something like abstracting your code too much? Which of the following is the better option. We come from different coding languages so I am explaining this the same way I would to him. Assume everything below as summaries to what your respective languages would do.
IMPORTANT CONDITIONS THAT WILL ALWAYS BE EXIST:
- There is only 1 table and 1 db
- There will only be a GET_ALL. No partial or specific collections.
- FACTORY CLASS and HELPER CLASS will always be called together NO MATTER WHAT.
FACTORY CLASS { //This method will check cache and create a repository instance of the table if one does not exist createNewRepository(); //This will collect the records from the instantiated repository getAllFromRepository(); //This will return the data that was collected returnData; } or
FACTORY CLASS { //This method will check cache and create a repository instance of the table if one does not exist createNewRepository(); } HELPER CLASS { //This will collect the records from the instantiated repository getAllFromRepository(); //This will return the data that was collected returnData; } We both have different views on the SOLID principles apparently.
I believe a class should have single responsibility in the sense of "This factory class' responsibility is to get me the data from the db" that will include the functionality required to achieve this.
He believes a class should have single responsibility in the sense of "This factory class' responsibility is to spin up the repository and not to call the data. A helper class will call the data"
I agree with him if it was the case that there was different variations of how the data is called but because the data will always be checked>createdIfNull>collected and this entire process is the functionality of "accessing the data to use" shouldn't it be in a single class?