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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:23:38+00:00 2026-05-24T08:23:38+00:00

I have this C# class structure that I would like to refactor to use

  • 0

I have this C# class structure that I would like to refactor to use best coding standards (use interfaces/abstract classes) so it can be more maintainable and reusable. The code as it is right now isn’t awful, but it’s not ideal.

I have a series of TableItemGroup classes: AccountTableItemGroup, PendingVoteTableItemGroup, and RequestingVoteTableItemGroup. Each TableItemGrup contains a string SectionName and a List for its corresponding TableItem …as such:

public class AccountTableItemGroup {
    public string SectionName { get; set; }

    public List<AccountTableItem> Items
    {
        get { return this._items; }
        set { this._items = value; }
    }        
    public List<AccountTableItem> _items = new List<AccountTableItem>();

    public AccountTableItemGroup()
    {
    }
}

In the future there will be many more TableItemGroups and if they are all the same except for the List part, I don’t want to have to copy the code and create a new Group every time and make that small change. I know there must be a better way. I would like to keep using the List<> generics so I don’t have to cast anything later though.

The other part are the TableItems. I have AccountTableItem, PendingVoteTableItem, and RequestingVoteTableItem. The TableItems are different from each other, but they each share three common strings — TitleLabel, DetailLabel, and ImageName. But after that, each TableItem may or may not have additional properties or methods along with it ..as such:

public class AccountTableItem
{
    public string TitleLabel { get; set; }

    public string DetailLabel { get; set; }

    public string ImageName { get; set; }

    public bool SwitchSetting { get; set; }

    public AccountTableItem()
    {
    }
}

So my question to all of you is, how do I redefine my class structure to allow for as much reuse of code as possible and to use best coding standards?

I was thinking of having an abstract TableItem class or use an interface for the TableItemGroup? I know that using an interface or an abstract class is best for coding standards, but I don’t see how it would cut down on the amount of code I will have?

Thanks a lot for any help.

  • 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-24T08:23:39+00:00Added an answer on May 24, 2026 at 8:23 am

    Consider using generics to represent the TableItemGroup container, and make a base class for your TableItem, which you can inherit from for specific types of table item. If you inherit directly from List<T>, then you can treat your item group as a collection without having to use the Items property as in your existing design.

    There’s not much point in using interfaces for these sorts of types. As they stand they are data classes so have no behavior. If they had behavior, using interfaces would make sense as you would then be able to change implementations and so vary behavior.

    public class TableItemGroup<T> : List<T> where T : TableItem
    {
        public TableItemGroup(string sectionName)
        {
            SectionName = sectionName;
        }
    
        public string SectionName { get; private set; }
    }
    
    public class TableItem
    {
        public string TitleLabel { get; set; }
    
        public string DetailLabel { get; set; }
    
        public string ImageName { get; set; }
    }
    
    public class AccountTableItem : TableItem
    {
        public bool SwitchSetting { get; set; }
    }
    

    Now that we have a generic TableItemGroup container, you can re-use this for all TableItem types. Having a base class for TableItem again gives you some re-use.

    var items = new TableItemGroup<AccountTableItem>("Accounts");
    
    items.Add(new AccountTableItem { SwitchSetting = true });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.