Reputation: 4003
part of the application am developing is presenting a form to the user and requesting them to either decline it/accept it. There are thee types of users that will need to approve the same form so that it is considered accepted. The suggestion I need is this: What structure can I use/best use to store the user type and their response? So far I have an object that is Approvers. This holds the three types of users with setters and getters (and other methods related to operations). I also created another object that is UserDecisions where i have two attributes to set, they are: Usertype & response. But I can't think of how to link them together or if there is a better way altogether? Thanks,
P.s. things i've considered were 2D arrays & hashmaps.
Upvotes: 0
Views: 141
Reputation: 55897
Suppose that you have
User { name, type }
// type is perhaps an enum with values such as administrator,
// manager, seniorManager, executive
Response { user, decision }
// decision is an enum "pending", "approved", "rejected"
Role { name, minimumTypeOfUser }
// first approval can be done by administrators or above
// second approval by managers or above
// third approval by executives only
Approval { Role, Response }
ThingToBeApproved { detalsOfWhatNeedsApproving, approvalList<Approval> }
// when you set up the approval list you specify each
// approval role and then select a user whose type matches
// the role.
In systems I work we decouple the Users from the Roles for doing a task - a more senior person on occasion fulfils the junior's role.
Upvotes: 1
Reputation: 736
Create a base class for Users. Extend them to create your own customized user class such as Approvers. In UserDecisions Class, create a filed for formName or userName which will link UserDecisions with Users. Or you can create a seperate class for linking purpose.
Upvotes: 1
Reputation: 160181
A "de-normalized" system would have User
s, a UserType
enum (or similar), and a collection of User
=> Response
s. A map is fine; it speeds up making sure a user doesn't vote twice.
If you need to aggregate answers by UserType
you could keep a separate tally of UserType
=> Response
s updated as responses are tallied.
Upvotes: 1