Page 1 of 1

Class structure

Posted: Thu Sep 27, 2007 10:50 am
by GeXus
How do you guys setup your class structure? As in, how do you typically break it up? Do you have one class per file or one big file with all classes...

Posted: Thu Sep 27, 2007 11:03 am
by feyd
Class per file unless they are skeleton/minimalist that are highly related classes.

Posted: Thu Sep 27, 2007 11:36 am
by Maugrim_The_Reaper
One class per file is the easiest to maintain and organise - you can use any number of tools afterwards to aggregate source code in one giant file to maximise performance if needed.

Posted: Thu Sep 27, 2007 11:55 am
by GeXus
Do you separate classes based on area of the site? for example, I have classes that I use primarily for the admin area, however some of the methods I would still use outside the admin.... would you create new ones or keep them all in one class dir and just use them where ever?

Posted: Thu Sep 27, 2007 12:28 pm
by feyd
Directory structure wise? I segregate my classes based on categories. We've had a few discussions on that, so instead of rehashing my response, I'll simply link to one of them:

viewtopic.php?t=46498

Posted: Thu Sep 27, 2007 11:45 pm
by EricS
I separate each class into it's own file. I also stick to a standard naming convention for those classes and files which allows me to autoload the classes I need in the most efficient manner possible. I also wrote my own autoloader which is optimized for looking in the most commonly used folders first.

As for segregation. I really liked the directory structure used by Rails so I more or less duplicated it.

Re: Class structure

Posted: Fri Oct 19, 2007 9:52 am
by thinsoldier
GeXus wrote:How do you guys setup your class structure? As in, how do you typically break it up? Do you have one class per file or one big file with all classes...

I have 1 file for any class that's a lot of code or extends some built in php class.
For something like my form field building class where theres FormField and then an extended class for each type of field, since they're all so related I have them in a single file.

For use with autoload() I have to make special cases in my autoload function for files that contain multiple classes. Not a big deal.