calebbee — 2012-11-09T22:36:05-05:00 — #1
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?
john_betong — 2012-11-09T23:08:49-05:00 — #2
General rule of thumb is the class should be called after a noun and all methods should be verbs.
cups — 2012-11-10T06:05:09-05:00 — #3
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.
calebbee — 2012-11-10T07:07:59-05:00 — #4
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?
cups — 2012-11-10T11:59:56-05:00 — #5
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?
calebbee — 2012-11-10T16:25:51-05:00 — #6
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?