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?

General rule of thumb is the class should be called after a noun and all methods should be verbs.

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. :slight_smile:

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?

It depends … :wink:

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?

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?