Page 1 of 1

Size of classes and/or class design

Posted: Tue Nov 08, 2005 5:02 pm
by dallasx
Would it matter if I had a giant class behind the public_html that stored all my user functions? User functions meaning actions that users can perform on my website based on an access level.

Am I thinking about this the wrong way or is a better way to divide up the classes by department?

Code: Select all

// example
class UserFunction
{

    //class properties

    //15 Marketing functions

    //40 Accounting functions

    //30 MIS  functions
}

Posted: Tue Nov 08, 2005 5:25 pm
by s.dot
I believe it is just a matter of how you want to do it.

I have such a page that performs all the actions (not a class) and I have it inside the public_html folder. Of course throughout this page, there are checks inside of the action that makes sure the user has the appropriate permissions to perform the actions. My page that I have is around 60kb in size, and I don't notice any difference at all having it in one 'giant' page. In fact, it makes it easier for me to go and update the scripts since I have all the form actions in one area.

Posted: Tue Nov 08, 2005 6:42 pm
by McGruff
You can store included files off root and it's recommended to do so in order to prevent the possibility of hackers running your code in ways you didn't intend.

Putting all those functions in one class wouldn't be so good. The functions themselves may be trying to do too much unless they are merely calling on other objects to which tasks are delegated. An accounting action such as "enter sale" might involve a whole range of domain objects, classes which save to database, and classes which create a final view - possibly a page which summarises the action taken or maybe a sales listing.

Ideally you want smaller classes which do just one thing. I would expect to have dozens to carry out an "enter sale" action (or almost any kind of action for that matter).

Posted: Tue Nov 08, 2005 7:29 pm
by alvinphp
If you are going to put everything in one big class then why even have a class? Just create an include file with all your functions in it.

Posted: Thu Nov 10, 2005 8:34 am
by BDKR
alvinphp wrote:If you are going to put everything in one big class then why even have a class? Just create an include file with all your functions in it.
Exactly! There is a famous anti-pattern called a God Class (aka "The Blob"). This one would certainly qualify as a minor diety.

http://www.antipatterns.com/briefing/sld024.htm

Dat otta leaoirn ya! LOL