I am developing a site where I have once class file that deals with a few database tables.

My question is:

Is it better to have one big file (the class) and then require only this file or have a class for each table and then have more require statements in my code?

Thank you

3 Years
Discussion Span
Last Post by jkon

Both options can be fine, it all depends on what your class is supposed to do. There is no one correct answer to this question.


Thank you, was just wondering if one has better performance than the other.


There is no one correct answer to this question, both the options are good it depends on what your class is supposed o do.

Votes + Comments
copycat answer :(

I don’t think the question has to do with Autoloading vs Combining classes into a single file. The latter (combining classes into a single file) hurts the clearness of OOP architecture in my opinion. The question here in my point of view is very interesting and common.

If you have different tables in the same business model then probably each one of them represent a different data structure. Having that on mind would be a good idea to build different objects for each table. Along with those objects you could have data workers classes for each one of them (to create , insert , update , delete or what ever) and assigners classes to assign the values that you are getting from db to an object or to a list of objects. (data workers and assigners have also meaning in logical fraction of business model -and not one to one to db tables- basis).

After that of course you can have a super object containing other objects or lists of them. And an assigner that will use all the others assigners needed to do the job. I am emphasis this architecture because usually I see it the other way around. The opposite is to create really complex objects with mixed data workers that get data from various db tables. At first view this seems the same if you only want the final super – object , but 1) it is not clean in my point of view and 2) troubles you when you only want to work with a part of that super – object ( an object that is a property of it or a list of objects that is a property of it), also I have seen many approaches to that, as switchers not to get certain parts of the super-object , but this clearly demonstrate that there isn’t a good understanding of what OOP is.

Again this is my point of view, I find this topic really interesting, and my practice have changed over the years working OOP in various languages. At first years working strictly in OOP I was making really complex objects and worked with them. As the time goes by , I ended creating simpler (and cleaner) objects in their logical context and then build up the architecture needed by the business model.

Edited by jkon

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.