mardi 19 janvier 2021

Can we put list of things done in a class

I was practicing object oriented design and came across few problems.

  1. Can we put list of things done by a user in user class. For example in stackoverflow design, can I put list of comments, list of answers and list of questions made by specific account in class UserAccount. I have seen a lot of websites where they include the things done by someone in that only. But, when I asked my friend, he said that we should not put these things into the class itself but, we should have another class responsible for maintaining the data and that should handle all these things. Account should just have password, name address and nothing else.
  2. I have seen on websites where they have a function blockAccount in AdminAccount class which takes no args. I want to know how can they block from the AdminAccount class itself. Do they keep the user data in AdminAccount class but, then it violates what I mentioned in number 1 point.
  3. I have seen codes where they designed a shopping app and they had checkOutCart option in UserAccount class. How can they do that since we have to put the order placed in the database too. So, do they return the order object formed from inside the checkOut function.

I exactly want to ask how do you people look for what exactly I have to keep in the class. I got the point that we can have a userService class but, then what is the meaning of userAccount class if everything is to be done through userService. Is userAccount class just to store user's info.

Aucun commentaire:

Enregistrer un commentaire