×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

inheritance question

inheritance question

inheritance question

(OP)
I am designing a system trying to use object oriented design. I have a question about inheritance.  I work for a kosher certifying agency. The agency has employees that work in the office or inspect factories. The same employee can do both. There are also employees who are called administrators who can also be inspectors.  I thought I would a class called employee and then two classes that would inherit from employee called inspector and administrator.Is there any problem from a OO design standpoint if the same employee can be both and also be an employee at the same time?

Thanks
Judy  
 

RE: inheritance question

this scenario is similar to user/roles; where a user can have many roles and roles can have many users.

CODE

interface User
{
  void RemoveRole(Role role);
  void AddRole(Role role);
  bool IsInRole(Role role);
}
it's usually good practice to favor composition over inheritance.

Jason Meckley
Programmer
Specialty Bakers, Inc.

RE: inheritance question

If it was me designing the system, I would draw a data model out also to show how the employees and the different sub-types all relate together; this may help you to identify what is common, what is inherited, and (possibly) additional class definitions required.

Greg  

RE: inheritance question

I think Jason is right, this model is widely used for managing permissions. In the future if you need to change or add some new types of permissions all you have to do is to add a Role. In most cases you don't even need to add a new class.

From the data model perspective the role represent just an attribute of the user.

-------------------------------------------

Design Patterns and Principles

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close