How to model user system

Asked

Viewed 794 times

1

Need to model the classes of a system where will have 2 types of User, the common user and the administrator, what is the best way to model this? Well I will specify the attributes that each one needs in my application:

Common user: name, login, password, email, age, address etc...

Administrator: name, login, password, email...

What’s the right way to model yourself? I thought the following:

Abstract User Class:name, login, password, email.

Common User Class inherits User, and will have its particularities.

Administrator class inherits User, and has nothing to +.

Is it right for an administrator to be without any particulars? For if he inherits User, it is already done, or if the administrator class will be blank, that is correct? if not which is the best way? thank you

  • 1

    Do you want to model a technology-independent user system? There are Frameworks that already do this work for you, but rely on technology.

  • I want a model only, this is for any technology.

  • 2

    I still defined myself on this question, I do not know if it is not clear or is very broad. In my conception it is difficult to answer it. Unless you just want to know if your initial idea is good, if there are any problems in general. If so, you are on the right track, nothing wrong. But without details, it’s hard to answer. Deep down if you have all the details you will almost have the answer for yourself and then there may be very specific questions that probably fit perfectly here.

  • 2

    I do not see why the distinction between ordinary user and administrator, since the administrator is no longer a user with all the privileges of the system (or at least the "configurational"). But the question is very based on opinions, complicated to answer...

  • 1

    You just started modeling and are already using inheritance? Inheritance is to use when you need, not to use just because it exists. Your modeling is wrong; use attributes or user groups to distinguish permissions and not inheritance. Also, the question is very generic, does not offer enough details for a good answer.

2 answers

2


A widely used alternative is to separate the concepts of User and Person in their own classes.

Thus, user contains data relating to the use of your application, such as login, password, date of last access, password expiration date, and security permissions given to this user. A user doesn’t even need to be a person, it can be another system accessing yours via an API. In your case you can even create an Administrator user who does not have personal information but has all permissions.

On the other hand, person represents the information of an individual, such as name, date of birth, dependents, addresses, telephones, sex, etc. A person also does not need to be a system user (imagine a child or a user’s wife.)

So much user as person may have a reference to each other, type pessoa.IDUsuário or usuario.IDPessoa.

  • Precisely. If to access the system a user does not need additional information, the additional information belongs to another +1 entity.

0

I don’t know what the level of complexity of your system, but since all attributes are equal an idea was you have a single user class and have an attribute called level or levelDecesso to control this, for example Administrator being 0, and Common User 1. On small systems I have already used this and solved, so it depends on your system, if it is something more complex you can do a search for some Security Framework, if it is in java for example I know the Spring Security.

  • I already tried this solution, however they are not the same attributes,the common user he has Age, address, thing administrator does not have, so if I create a level field, in the register of the administrator, several fields would be blank, what for me is not the best way, my question is if my solution is correct, or if you have another idea...

  • What you did then is correct yes, it is correct yes the Administrator be without any particularity, in case he gets only what he inherited from the same user.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.