Page 1 of 1
Having classes on the same file?
Posted: Thu May 28, 2009 7:21 pm
by kaisellgren
Hi,
I was wondering that does anyone ever put abstract classes or interfaces in the same file with their "real" class equivalents? This way you could save some execution time, but makes the class file a bit larger..
Re: Having classes on the same file?
Posted: Thu May 28, 2009 7:49 pm
by Christopher
That seems wrong because the point of an abstract class is to provide a base class for other classes to extend. If you have the abstract and child class in the same file it implies that they should be combined.
The only time I combine classes is for 1) helper classes used by a larger class that would never need to be autoloaded, 2) combining many classes to speed loading.
Re: Having classes on the same file?
Posted: Thu May 28, 2009 8:16 pm
by kaisellgren
Would this be an acceptable solution for production use (leaving the developer version intact - separate files)?
Re: Having classes on the same file?
Posted: Thu May 28, 2009 11:28 pm
by alex.barylski
I keep all classes in separate files and run a compile like script to pull classes into a single file (cached actually not compliled). Each request pulls on different classes, so each request loads a different cache.
The only problem I have ran into using this approach is when the cache is out of date and the classes are not loaded completely...I basically need to run my application through a ringer to ensure the classes loaded on each request are properly cached...which also means I completely test my application.
I`m looking into maybe using Selenium to automate the process as I currently use iMacros for Firefox which is a little tedious.
Re: Having classes on the same file?
Posted: Fri May 29, 2009 6:40 am
by kaisellgren
PCSpectra wrote:Each request pulls on different classes,
How do you determine, which cache to load?
Re: Having classes on the same file?
Posted: Fri May 29, 2009 11:35 am
by alex.barylski
Each request is associated with a URI -- so the cache are just MD5'd URIs
Re: Having classes on the same file?
Posted: Fri May 29, 2009 1:32 pm
by kaisellgren
PCSpectra wrote:Each request is associated with a URI -- so the cache are just MD5'd URIs
Are you sure you never miss any required classes?
Re: Having classes on the same file?
Posted: Fri May 29, 2009 1:41 pm
by Darhazer
In the framework we use, small related classes are put together in one class. For example all basic actions (create / execCreate, edit / execEdit, view, delete ) as well as their abstract classes they extend, are in 1 files, but those are type of command patterns and they are really small. Same applies to all validator classes, and to all basic widget classes. When we are creating a set of specific validators that all applies to the same view (screen in the browser) we also put them in one file.
Sometimes module classes are also combined in one file.