Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 326
thomas Avatar asked Sep 04 '26 05:09

thomas


2 Answers

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.

like image 125
GSto Avatar answered Sep 06 '26 17:09

GSto


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.

like image 28
David Brunelle Avatar answered Sep 06 '26 18:09

David Brunelle