Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple question 1

Status
Not open for further replies.

mmaz

Programmer
Nov 22, 2000
347
Hello,

I have *very* little experience in OOP, but I've managed to build a simple application that lets users manage a directory of companies (in Java). Now, I have to insert authentication functionality.

The user interface will look a little different upon login. If they're administrators, they can insert, modify & delete data. If they're regular users, they can do all these things, but the changes will have to be approved by the administrator. So the administrator interface will have 2 extra buttons, "Approve Change" and "Reject Change".

What would be the best way to achieve this? Should it be something like:

-build 2 button panels, one for Administrators and one for Users
-when user logs in, create User object
-if person is Administrator, use Administrator button panel, else use regular button panel

Does that look okay? Suggestions, anyone?

Thanks,

Marie


 
Don't be afraid to start with a non-optimal design. If the difference you describe is the only difference between a regular user and an administrator, you could just create a
Code:
User
class with an
Code:
isAdministrator
property if you like. This may not win a beauty contest, but it communicates what it is doing and you can always refactor it later if needed.

You could then use the same panel for all users and hide the two buttons for regular users.

If you want more elegant options, a
Code:
Rights
class would come to mind, with a
Code:
mayApprove
property and maybe other rights. Each
Code:
User
object then gets an instance of this
Code:
Rights
class, so all code that has to deal with the rights of a specific user can just query the associated rights.

If you see that your code does an awful lot of querying, the time is right to create an abstract
Code:
User
class and have the
Code:
Administrator
and
Code:
RegularUser
classes inherit from it.

As I said before, a non-optimal design may not be that bad. And you can always refactor it when you need it.

Best regards
 
Thanks for your reply, DonQuichote. It's very helpful!

Marie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top