Back to list
Views:   7.6K
Replies:  1

Initialize Object based on Role

I have a question on how to initialize an object based on user role.

For example, say, I have an abstract class User. There exist 3 different kinds of user Admin, Member, Moderator,
Every one has it's own set of functionality

How do I initiate an object of a particular type based on user role?
Suppose I have an abstract class User with a property Role which is an Enum.
I would like to code it like this

User user = new User();
u.Role = UserRole.Admin;

then Object user must be decorated with the properties of Admin.

I just want's to know how do I change it?
Here is what I was trying to do... is shown in Code block below

Please Reply


Asmprogs Asmprogs, Oct 09, 2010
Reply 1

Perhaps something similiar to the State pattern would work. However, your question seems contradictory, at least to me, in term of semantics

You mention each kind of user has it's own functionality and then you mention that properties must be set for each type of user. There is a difference on how you would implement this based on which statement is correct. Functionality implies 3 sets of business logic, properties are just that.

p.s. you didn't appear to attach any code.

Chris Bint, Oct 11, 2010
Stay Inspired!
Join other developers and designers who have already signed up for our mailing list.
Terms     Privacy     Cookies       Do Not Sell       Licensing      
Made with    in Austin, Texas.  - vsn 44.0.0
© Data & Object Factory, LLC.