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

The Archive Base Latest Questions

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

I hava a base type (A) which has two derivatives (B and C). The

  • 0

I hava a base type (A) which has two derivatives (B and C). The base type is not abstract. So, I have three objects.

The only difference between B and C is that they both have one extra different property:

  • B.Foo
  • C.Bar

Now I have conditions like this in my code:

if(myObject is B)
     myDatabindB.DataSource = ((B)myReport).Foo);
else if(myObject is C)
     myDatabindC.DataSource = ((C)myReport).Bar);

and in another method:

pnlSomePanel.Visible = myObject is B;
pnlSomeOtherPanel.Visible = myObject is C;

But you can imagine that when there’s a new type I have to update all my if-else statements. This violates a lot of OO principles.

But the problem is that I can’t think of a nice and clean solution to solve this issue.
Do you have a suggestion / idea to solve this problem?

EDIT:
If it matters, I am using the MVP pattern.

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

    First, it’s good that you asked this with only three items–it makes fixing problems much faster :). Your code’s very generic, so I can only offer generic solutions.

    The big goal here is to increase the encapsulation of classes A, B, and C–to make sure that anything relevant to A, B, or C is stored within those classes and not moved to, say, if-statements elsewhere.

    We can move the logic for figuring out what the correct datasource is from the Controller (which is doing your binding) to your report. This method’s name should be descriptive, like GetReportSubjectLine().

    class A{
        <snip>
        public virtual SomeDataType getDataSourceForViewType(){
         throw new NotImplementedException()
        }
    }
    
    class B{
    <snip>
    public override SomeDataType getDataSourceForViewType(){
        return this.Foo;
        }
    }
    
    class C{
     public override SomeDataType getDataSourceForViewType(){
        return this.Bar;
        }
    }
    

    This code will be reusable if you ever want to make different UI’s that still need this type of information from your report to generate whatever graphical view you’re generating.

    There’s no good way around the second problem you presented. We could always move the panel visibility into the reports too, but that increases coupling–how much one class is tied to another–way too much. Your reports should not be tied to a specific view.

    The best solution is to add another layer of indirection–in this case, an intermediary class to handle the logic of what panels to make visible when. This way your controller doesn’t have to bear the responsibility of managing panel visibilities itself.

    public class PanelVisibilityManager{
        ICollection<Panel> ManagedPanels {get; set;}
        //
        public IDictionary<System.Type, ICollection<Panel>> Switchboard {get; set;}
    
        public void TogglePanelsFor(System.Type item){
            foreach(var panel in ManagedPanels){
                panel.Visible=false;
                }
            foreach(var panel in Switchboard[item]){
                     panel.Visible=true;              
                }
    
    }
    

    Hope this helps!

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

Sidebar

Related Questions

i hava two text boxs in flex.have to add two txt boxs values in
I hav a base class which is abstract. I am inheritting a new class
I hava a simple set of two related tables of an 'order' that has
I hava a thread in which I have an infinite loop, doing some network
I hava a data window object, in which I am fetching some attributes from
I hava a php variable that contain JSON type data. $list = [{id:10,first_name:first,mi_name:,last_name:last,nick_name:HH}]; and
I hava a website with a navigation bar which consists of several tabs. Now
I hava an absolute url in my stylesheet. http://localhost/images/myimage.jpg . I also have a
I hava a main view, where you have one object and you can change
I hava a datalist in side that I have checkbox <asp:DataList ID=dlst1 runat=server RepeatDirection=Horizontal

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.