SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2012
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What should a class contain?

    Hey guys! I've been using classes for a couple of projects now, and i can't help but wonder if i'm using them efficiently or not. What exactly should a class have in it? Should there be a register user class that has just methods for registering, or should the class also contain components for logging in? What's the general rule of thumb for using classes?

  2. #2
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,822
    Mentioned
    73 Post(s)
    Tagged
    6 Thread(s)
    General rule of thumb is the class should be called after a noun and all methods should be verbs.

  3. #3
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by calabbee
    Should there be a register user class that has just methods for registering, or should the class also contain components for logging in?
    Your question suggests you may have arrived at a point of "analysis paralysis" which I am sure many of us will recognise and commiserate with you for - not wanting to do it wrong but not sure where to start because each planned move might break some rule or principle -- is that the case for you?

    Why not show us what you've got --or just where you've got up to -- and then the we can all argue over whether we think you are doing it "right". There is no absolute "right" as ever, because so much hinges on "it depends...". There are only principles which ought to be applied and these are open to interpretation.

    This SP forum excels because various users here pipe up and each interprets those principles in different ways and openly discusses them. Its up to you to make the first move though, to cast any humility aside and bare all.

  4. #4
    SitePoint Enthusiast
    Join Date
    Jul 2012
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Cups View Post
    not wanting to do it wrong but not sure where to start because each planned move might break some rule or principle -- is that the case for you?
    I think that's exactly the case! Right now what i have is the one class that has both register and login methods in it. I'm currently thinking about how to go about programming for an admin page for a client (probably an entire crud application). It would have a lot of different functionalities, so it would have a lot of different class, right?

  5. #5
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    It depends ....

    Your user class is handling logins you say.

    Does that involve sessions, database interactions and come with error handling and logging?

    Or does it delegate some of these tasks to other specialist classes?

  6. #6
    SitePoint Enthusiast
    Join Date
    Jul 2012
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes, i involves all the session, database, etc. stuff that goes with logins..it actually seems to be a better idea to have specialist classes that do that. Is it?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •