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 6548691
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:00:01+00:00 2026-05-25T12:00:01+00:00

In [ this post ], I’m struggling to implement a State Pattern as @jonp

  • 0

In [this post], I’m struggling to implement a State Pattern as @jonp suggests. I don’t quite get how to use what’s he’s posted but it leads to the thought that maybe I’m trying to fit a square peg into a round hole. So my question:

If I have a visitor to my site that can play multiple roles i.e. a User could be a Vendor, an Employer, an Advertiser, OR all of the above, should I be using inheritance? I’ve declared:

class Vendor : User {}
class Advertiser : User {}

et cetera, but when a user is both a vendor and an employer then instances of different classes really point to the same underlying object… I’m not sure this can work. How do I model it?

* update *

thanks everyone (you all get a point (it’s all I can give)). I’ve been pulling my hair out over deep-copies with EF, downcasting and the state pattern for the last several days. The role approach makes much more sense.

  • 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-25T12:00:02+00:00Added an answer on May 25, 2026 at 12:00 pm

    This sounds like a situation to which the attribute pattern (or so I call it) would be very appropriate. It’s a much more loosely-coupled approach than simple inheritance that can be used to specify multiple “behaviours” or in your case kinds of User. It’s really nothing more complicated than an object having tags of another kind of object.

    The easiest way to implement it would be to have a concrete User class, with a read-only property IList<UserRole> (internally this can be a List<T> field perhaps). Your UserRole class would then be abstract, and VendorRole/AdvertiserRole/etc. would derive from it, allowing you to tag on an arbitrary number of different roles (even ones of the same type) onto a given user. These roles can in addition define their own custom behaviours, utility methods, etc.

    In addition, you could define a GetRole<TRole> method on your User class to facilitate access to roles of a specific type (assuming each User only has a single Role of a specific subtype).

    Side note: you may also consider the decorator patern, which is closely related to the above mentioned pattern — though personally I feel it is overkill here, and really adds nothing in terms of flexibility or power. It often just obscures what you’re trying to do; though feel free to investigate anyway.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Following this post which I posted some time ago, I now get the same
This post relates to a previous that i posted but the question is different
(This post has been submitted on the Yootheme forums but I don't have as
This post asks this question but doesn't really give an answer, so I thought
This post started as a question on ServerFault ( https://serverfault.com/questions/131156/user-receiving-partial-downloads ) but I determined
So this post talked about how to actually implement url rewriting in an ASP.NET
This post is a duplicate from superuser.com, but since I had no answers, I
This post is similar to this post , but not exactly, so I'm asking
This post contains a lot of code, but I would really appreciate it if
This post is similar to one I have posted before about a dropdown filtering

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.