Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6623929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:35:28+00:00 2026-05-25T21:35:28+00:00

I have a basic User model that satisfies all the needs of a generic

  • 0

I have a basic User model that satisfies all the needs of a generic user. I now need to create several different roles for the user, each with about 10-20 different methods that are unusable by the other roles.

Assume that I have to load the generic User class to determine the user’s role…

Since it’s inefficient and heavy to package so many different role-based methods into the generic User model (when they can’t be utilized by all roles), what is the best way to give user’s access to their role-based methods ONLY when they need them?

Here are some ideas I’m tossing around:

  1. Have a separate class of services per role, and give them to the User class according to the user’s role

  2. Simply lug around all the methods in the user class, and only allow access to each when the user has the correct role.

  3. Totally refactor and make the role based classes inherit from the User class.

Are any of these good ideas, or is there a better idea at all?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T21:35:28+00:00Added an answer on May 25, 2026 at 9:35 pm

    Why not just composition the role based classes into the User object?

    $user = new User(/* pass role as an arg */);
    
    // Internally:
    // if ($user->getRole() instanceof AdminRole) or similar...
    if ($user->isAdmin()) {
        // AdminRole::doSomethingAdminish()
        $user->getRole()->doSomethingAdminish();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a user control that is pretty basic. It contains several TextBox controls,
In my application I have some basic user information that needs to be displayed
I have a pretty basic Paperclip Upload model that is attached to a User
Lets say we have some basic AR model. class User < ActiveRecord::Base attr_accessible :firstname,
I have a multipart form that takes basic user information at the beginning with
I have a basic CRUD form that uses PageMethods to update the user details,
I have a django server that serves the basic site with user, auth etc
I have a Rails 2.3.x app that implements the act_as_authentic in User model and
I have an Account model that has_one User model, and a User model that
I have a basic FK to user, call it owner class Baz(models.Model): owner =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.