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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:26:00+00:00 2026-05-27T20:26:00+00:00

Following is the structure of my class public abstract class BaseUser { protected List<Perm>

  • 0

Following is the structure of my class

public abstract class BaseUser
{
    protected List<Perm> permissions;
    public abstract void AddPerm(Perm perm);
}

public class NormalUser : BaseUser
{
    public override void AddPerm(Perm perm)
    {
        throw new InvalidOperationException("A normal user cant add permissions");
    }
}

public class SpecialUser : BaseUser
{
    public override void AddPerm(Perm perm)
    {
        if(permissions==null) permissions=new List<Perm>();
            this.permissions.Add(perm);
    }
}

class Container
{
    List<BaseUser> users;
}

What is required:

  1. Container will keep both types of users
  2. SpecialUser will have the functionality of add permissions – Done
  3. Normal User will not be allowed add permissions – Done

    I have chosen strategy pattern to achieve above

    The thing I am not able to achieve is

  4. Both Types of users will be hydrated from the Database (The users will be initialized with list of default permissions)

Am I right in choosing this pattern in this situation? If yes then how do I address requirement 4?

Many Thanks,
asolvent

  • 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-27T20:26:00+00:00Added an answer on May 27, 2026 at 8:26 pm

    The example your provided is not really an instance of the strategy pattern, it is just a method override. The strategy pattern involves a context object and a strategy object. Regardless, I would try to avoid the temptation to apply OOP in all possible places. Instead of inheritance consider using a UserType enum and a simple if statement to support the required behavior. This makes it easier to map to a database and also keeps the code simple:

    enum UserType {
     Normal,
     Special
    }
    
    class User {
    
    public UserType Type { get; set; }  
    
    public override void AddPerm(Perm perm){
      switch (this.Type) {
     // logic goes here
      } 
     }
    } 
    

    This type of problem is a recurring theme in using OOP in enterprise data driven applications and I normally try to keep things as simple as possible. Do you really need to derive a base User type to provide the required functionality? Will it have additional behaviors and properties?

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

Sidebar

Related Questions

I have the following structure: abstract class Base { public abstract List<...> Get(); //What
I have a follwing class structure: public abstract class AbstractFoo { public virtual void
I have following structure of my entities: @MappedSuperclass public abstract class BaseEntity { @Id
I have the following class structure public class Outer{ private Mapper a; .... private
I have the following class structure: class Organization { string Name; List<User> users; List<Organization>
I have the following class structure class Top : NotifyPropertyChanged { private List<Inner> innerList;
Consider the following data structure: List<Person> People; class Person { List<Car> Cars; List<Hobby> Hobbies;
I have following code: public abstract class Operand<T> { public T Value { get;
I have a singleton with a following structure: // Hpp class Root : public
I have the following structure public class MyClass : MyBaseClass<System.Int32> { } In a

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.