views:

83

answers:

6

My system has an User class with a lot of properties: name, e-mail, address, phone number, etc. And it has also an UserAccount class with properties: username, password and salt. This is a blog application. UserAccount provides login and logout methods. Now I don't know who will be related with Posts. Should an User contains posts or an UserAccount? Thank you.

+4  A: 

While I'm not sure why you have User and UserAccount as separate classes to begin with, it sounds like you want UserAccount to be used solely for authentication, so based on the information you gave I would say to relate them to the User Object.

GSto
I don't want to give too much resposability to the user class. UserAccount acts like an auth class. Thank you.
thomas
A single user might have two accounts. Whether the system needs to reflect this fact is another matter.
DJClayworth
@DJClayworth, this is why i added my 'based on the given information' clause. That may well be the case, but I couldn't tell based on what was given in the original question.
GSto
+1  A: 

I think it depends if a user can have multiple UserAccounts. If yes, I would relate the posts to the UserAccount. Otherwise I don't think it really matters.

Roflcoptr
An user can have just one user account
thomas
+4  A: 

I guess this really depend on how you see it.

Does each user always have one user account or is it possible that a user have more then one user account (and vice versa). I think I would put it in the user class.

if it's a one-one relation, there really is no reason not to merge them together.

David Brunelle
It's one to one relation
thomas
+1  A: 

I would say to make it related to UserAccount, as that is where your Username is stored, which can identify your posts. Most people will not take kindly to automatically having their real name posted on the internet (Ala: Battle.net RealID).

shmeeps
+1  A: 

I would give the relation to the UserAccount class. That way you could implement the ability to delete an 'account' without losing their personal information (if that is a concern). Also it would make it easy for an individual to have seperate types of accounts (if your site is a social site then maybe each user could have a personal and a professional account, as an example).

Otherwise, it doesn't seem to make much difference so long as the User and UserAccount conceptually represent the same entity.

wllmsaccnt
A: 

IMHO Posts should be a separate class of it's own with username as the key/attribute

philar