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

  • Home
  • SEARCH
  • 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 3849930
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:55:52+00:00 2026-05-19T16:55:52+00:00

I want my site to support different subscription types, free, premium and etc. So

  • 0

I want my site to support different subscription types, free, premium and etc.

So far I made an abstract class that is like this

  public abstract class Limits
    {

        public int PostLimit { get; protected set; }


        protected Limits(int postLimit)
        {
            PostLimit = postLimit;
        }

        public bool IsLimitReached(int postCount)
        {
            return postCount > PostLimit 
        }

    }


 public class FreeLimit : Limits
    {
        private const int postLimit = 1;


        public FreeLimit()
            : base(postLimit)
        {
        }

    } 

So now I did this for all my account types. Now the problem is I don’t know how to actually use this class.

For instance I have a service layer call PostService and in this class I have

public void CreatePost(Post post)
{
  // do stuff here
}

Now in this method I don’t know how to check if they reached the limit. I don’t know how to check because I am unsure how to find out if I should be using the FreeLimit or PremiumLimit or what account they have.

I am thinking that I first have to figure out their Role and then somehow use that information to create the right class.

I guess I could have something like

public void CreatePost(Post post, PlanType planType)
{
   Limits limit;
   switch(planType)
   {
      case planType.Free:
         limit = new FreeLmit()
        break;
   }

    if(limit.IsLimitReached())
    {
      // do stuff
    }
} 

I don’t like this way as now for every method that needs to check a limit will have to do this. I will have a few methods that require this check in my service layer.

So I was thinking of putting it in my constructor but I don’t know if it is good to have a switch statement in a constructor.

  • 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-19T16:55:53+00:00Added an answer on May 19, 2026 at 4:55 pm

    You could use an interface ILimit

    interface ILimit
    {
        int PostLimit { get; protected set; }
        bool IsLimitReached(int postCount);
    }
    

    Now you can have several other classes (Free, Premium, Super) that implement this interface. In your service method CreatePost you can just pass any instance of a class that implements the interface and use it – there’s no need to distinguish them anymore since they all support the same interface.

    public void CreatePost(Post post, ILimit limit)
    {
        if(limit.IsLimitReached())
        {
          // do stuff
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to conform my site's string handling to support other languages per UTF-8.
I want to let site visitors download our company collateral, and would like to
Okay, so I want to make a polling site but it doesn't work like
In my site I need to give support for IE7. Now everybody knows that
I want to create site thumbnails through my web application, so I thought I
in my site i want to set default page to open, using this script
I want to have site wide default settings for all jQuery validation uses on
I want my Nancy site to accept Google/Facebook/OpenID authentication. Are there any existing solutions
I am creating a site and want to have individual pages for each row
I Have done a site but want to redirect it to another subdomain in

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.