0

I'm making a small record application for school work that has a login system with different user types. Each user type will have have different permissions on the app. Is there anything wrong with me having an int field in the User class that varies depending on permissions? E.g. 0 would have all access, 1 slightly less, etc.

Is there anything wrong with approaching the task like this instead of extending the default User class to other types of User?

oppiie
  • 1
  • What if you want to a user to have the rights 1,5,7 but not 2, 3, 4 and 6? What do these number even mean? Your current approach only takes into account that each "slightly less" access will work for all your users. Instead, you could define user groups. One user can belong to multiple groups. Each groups white-lists or blacklists certain rights; some may take precedence over others. It depends on your use-case. – k0pernikus Feb 14 '18 at 17:50

1 Answers1

0

A better way would be to model the permission as enum

enum Permission {
   FULL_ACCESS, RESTRICTED, NO_ACCESS;
}
public class User {
   //other fields
   private Permission permission; 
}

Edit: The above example was demonstrated in Java. You can have it changed to the way your language allows it to.

Thiyagu
  • 17,362
  • 5
  • 42
  • 79