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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T04:59:17+00:00 2026-05-15T04:59:17+00:00

In my app, I have deal with several different parameters, which derive from IParameter

  • 0

In my app, I have deal with several different “parameters”, which derive from IParameter interface, and also ParamBase abstract base class. I currently have two different parameter types, call them FooParameter and BarParameter, which both derive from ParamBase. Obviously, I can treat them both as IParameters when I need to deal with them generically, or detect their specific type when I need to handle their specific functionality.

My question lies in specific FooParameters. I currently have a few specific ones with their own classes which derive from FooParameter, we’ll call them FP12, FP13, FP14, etc. These all have certain characteristics, which make me treat them differently in the UI. (Most have names associated with the individual bits, or ranges of bits). Note that these specific, derived FP’s have no additional data associated with them, only properties (which refer to the same data in different ways) or methods.

Now, I’d like to keep all of these parameters in a Dictionary<String, IParameter> for easy generic access. The problem is, if I want to refer to a specific one with the special GUI functions, I can’t write:
FP12 fp12 = (FP12)paramList["FP12"] because you can’t downcast to a derived type (rightfully so). But in my case, I didn’t add any data, so the cast would theoretically work.

What type of programming model should I be using instead? Thanks!

  • 1 1 Answer
  • 4 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-15T04:59:18+00:00Added an answer on May 15, 2026 at 4:59 am

    There’s nothing really wrong with this approach, except for maybe storing the parameters in a dictionary. What is the purpose of doing that? Especially if you key them on their class name.

    I would just use a List<IParameter> and have a control go through the collection and pick the right subclass out of there.

    m_Parameters = new List<IParameter>();
    //This control needs FP12
    foreach(var param in Parameters) {
      var fp12 = param as FP12;
      if (fp12 != null) {
        //do something with the param.
        break;
      }
    }
    

    After writing the above I think I finally understand what you are trying to do. If you want to perform an operation that is available on FP12 on any subclass of FooParameter then you need to take that operation out of FooParameter altogether. Since your parameter is data and that data is the same across different subclasses of FooParameter, it makes sense to only have one implementation of FooParameter (“data” class) and multiple “operation” classes.

    //The one implementation of IParameter for all FooParameters
    public class FooParameter : IParameter {
      string Data1 {get;set;}
    }
    
    //base class for Foo Operation, only stores FooParameter 
    public class FooOperationBase {
      protected readonly FooParameter m_Param;
      public FooOperationBase (FooParameter param) {
        m_Param = param;
      } 
    }
    
    //specific operations on FooParameter go in this class
    public class FooOperation12 : FooOperationBase {
      public FooOperation12(FooParameter param) : base(param) {}
    
      public void DoSomeOperation() {
        return m_Param.Data1 + " transformed";
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have App A as main app. Now we build from it App B
I have app in which i have recorded sound files i want that i
I have an app that have several views. In one view I would like
I have a web app where I have several elements with class=classA . I
I come from a web background where I only have to deal with HTTP
I have an iPhone app which finds nearby coffee shops, then displays the details
I'm working on an google app engine app that will have to deal with
I have a Flex-based client app which talks to the back-end through BlazeDS. In
my app have action bar on top of windows. Where are some buttons. Buttons
In my app have a sign in activity. If login is successful, I start

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.