Skip to content

Instantly share code, notes, and snippets.

@taylorlapeyre
Created December 13, 2012 00:26
Show Gist options
  • Save taylorlapeyre/4272987 to your computer and use it in GitHub Desktop.
Save taylorlapeyre/4272987 to your computer and use it in GitHub Desktop.
Question: "If you were asked to design a role-based (users, moderators, admins, etc) user system, how would you approach the problem? Briefly explain."

Question 3

There would first be a base User class, which would take necessary attributes, such as an ID, username, password, etc. Users would be able to do anything that any user of the system can do - for instance, post a comment or submit something.

There would then be other User classes that inherit from the User superclass, such as moderators or administrators. These Users would have respective abilities which extend the basic User model. For instance, a moderator may have a ban_user action and an administrator might have the ability to edit other User's profiles.

Users would be perhaps kept in a UserList object that would contain a hash of users and their respective IDs. The UserList could be the superclass of a ModeratorList or AdminList. Alternatively (depending on the scale of the system), we could store the Users in a database - probably mysql - with tables.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment