Size of classes and/or class design

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
User avatar
dallasx
Forum Contributor
Posts: 106
Joined: Thu Oct 20, 2005 4:55 pm
Location: California

Size of classes and/or class design

Post 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
}
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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).
alvinphp
Forum Contributor
Posts: 380
Joined: Wed Sep 21, 2005 11:47 am

Post 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.
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post 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
Post Reply