lundi 8 août 2016

Reasons (not) to use attribute to differentiate object types

I'm developping a object-oriented Web Application that has only two types of users: common user and administrator.

Even though I learned a lot about inheritance and polymorphism, I'm tempted to ignore just that and add an attribute to diferentiate both users such that it is easyer to handle the user type managment.

Eg.:

class User{

String username;
String password;
int type;
// Type = 1, common user, default;
// Type = 2, admin, changed in database;
// Space for n other usertypes

}

All that I need is to differentiate allowance to access certain pages (users dont have special methods, just getters and setters).

I feel that this is a better approach because it can easily be done trough a session attribute.

Reasons why (not) to use this approach?

Aucun commentaire:

Enregistrer un commentaire