How to model user system

1

I need to model the classes of a system where you have 2 types of User, the common user and the administrator, what is the best way to model this? Well I'll 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 is the most correct way to model yourself? I thought of the following:

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

Common User class inherits User, and will have its peculiarities.

Class administrator inherits User, and has nothing to +.

Is it correct for the administrator to be without any particularity? because if it inherits User, is already done, ie the administrator class will go blank, is this correct? if not the best way? Thank you

    
asked by anonymous 15.11.2014 / 06:32

2 answers

1

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

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

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

Both user and person can have a reference to each other, type pessoa.IDUsuário or usuario.IDPessoa .

    
19.11.2014 / 16:17
0

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

    
15.11.2014 / 16:40