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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:46:34+00:00 2026-05-28T06:46:34+00:00

I have an abstract base class and two derived classes. The base class contains

  • 0

I have an abstract base class and two derived classes. The base class contains 6 properties which all can be maintained on a form.

The two derived classed both have 1 extra property. Those two properties can also be maintained on the same form.

In my form I have now code like this:

  btnSomething.visible = (myObject is DerivedA);
  pnlPanel.visible = !(myObject is DerivedA);

  if(myObject is DerivedA)
    myBindingSource.DataSource = myObject as DerivedA

  mySecondBindingSource = myObject;

I am not very happy with this approach, it smells. So my question is, what is a neat/good way to make this more OO? Because it is possibly that in the future DerivedC comes in…

I think this approach breaks the OCP principle (and probably other principles)

  • 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-28T06:46:34+00:00Added an answer on May 28, 2026 at 6:46 am

    You can use polymorphism and inheritance here:

    Define an interface

    interface ICommonFeatures
    {
        bool ContainsFoo {get;}
        //yak-yak
    }
    

    Then your derived classes implement it

    class DerivedA: ICommonFeatures
    {
        bool ContainsFoo {get {return true;}}
        //so-and-so
    }
    class DerivedB: ICommonFeatures
    {
        bool ContainsFoo {get {return false;}}
        //this-and-that
    }
    

    And when you use it, you deal only with the interface

    ICommonFeatures foo = new DerivedB();
    
    btnSomething.visible = foo.ContainsFoo;
    pnlPanel.visible = foo.Prop2;
    myBindingSource.DataSource = foo.CurrentDataSource
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an abstract base class which acts as an interface. I have two
I have a abstract base class A and a set of 10 derived classes.
If I have a base class and two derived classes, and I want to
I have an abstract base class T , from which classes A and B
Imagine I have abstract base class Shape , with derived classes Circle and Rectangle
I have a very simple scenario, using NHibernate: one abstract base class animal; two
I have an abstract base class and derived class: type TInterfaceMethod = class public
I have an abstract base class called Shape from which both Circle and Rectangle
I have an abstract base class that holds a Dictionary. I'd like inherited classes
I have a abstract base class that I have many inherited classes coming off

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.