tags:

views:

68

answers:

2

I'm building an Authentification library that's going to have around 45+ methods for dealing with user related stuff. However I've been wondering if it's actually recommendable to keep everything on a single file.

Is there a benefit on splitting my class into several subclasses and load them when needed?

I can always for example split the class into "mandatory" elements and the elements that only registered users need...

For example:

  • Mandatory Methods:

    • $user->is_logged()
    • $user->login()
    • $user->register()
  • Methods for Register...

  • Methods for logged-in user.
+2  A: 

It just depends on how you want to be including the class file(s) in your pages. If you want one simply include() statement for every page, then keep it all in one file. Unless your library is HUGE, the overhead from the other classes shouldn't be too much.

If you do it the other way, you'll simply be including different files based on the status of the session of the client.

Personally, I'd split them up as it's easier to edit them that way, but it's totally up to you.

BraedenP
The library is around 2,000 - 3,000 lines .. So I guess I should really split them..?
kuroir
Yeah, I'd split them up.. How many classes are we talking about? If it's a decent number to handle, then I'd actually make a file for each class, including each or creating "inclusion sets" for certain tasks that you need to perform. (Sort of like handling models in an MVC).If there are many different classes, then just make the three categories you suggested in your question as your "inclusion sets" and include them when necessary.
BraedenP
A: 

I'd go with the class/sub-class option.

You could then use a factory to return the correct type of user object based on the current URL or by simply specifying the desired type of user object if your particular setup doesn't lend itself to this.

middaparka