开发者

Relation between classes

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 provid开发者_如何学JAVAes 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.


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.


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.


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.


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).


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜