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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:57:10+00:00 2026-06-12T18:57:10+00:00

I have an abstract base class called WidgetBase which looks like this: public abstract

  • 0

I have an abstract base class called WidgetBase which looks like this:

public abstract class WidgetBase : Control, INamingContainer
{
     // This class declares abstract and virtual properties and methods but doesn't override anything
}

I have another abstract base class called ScrollerBase which looks like this:

public abstract class ScrollerBase : Control
{
    // This class has one abstract property and overrides OnInit and OnLoad
}

I need to create a class that inherits from both of these classes. Neither class can be converted to an interface. The simplest solution that I can think of is creating an extra WidgetBase class like this:

public abstract class ScrollingWidgetBase : ScrollerBase, INamingContainer
{
     // Lots of duplicated code from WidgetBase
}

It would be nice if I could do something like this:

public abstract class ScrollingWidgetBase : WidgetBase<ScrollerBase>    { /* Empty */ }
public abstract class WidgetBase : WidgetBase<Control>    { /* Empty */ }
public abstract class WidgetBase<T> : T, INamingContainer    { /* Code goes here */ }

However this isn’t possible. The only half elegant solution that I can think of would be something like this:

public interface IScroller { /* Overridable members go here */ }
public class WidgetBase : Control, INamingContainer
{
    protected override void OnInit(EventArgs e)
    {
        if (this is IScroller)
        {
            // Do scroller logic here
        }
    }
    protected override void OnLoad(EventArgs e)
    {
        if (this is IScroller)
        {
            // Do scroller logic here
        }
    }
}

public class Test : WidgetBase, IScroller {  }

However this would get very messy if more classes were created. Surely there must be some kind of design pattern that fixes this problem? Any help would be greatly appreciated.

Thanks,

Joe

  • 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-06-12T18:57:11+00:00Added an answer on June 12, 2026 at 6:57 pm

    As hyde said, you really would need to separate your behaviour from what your classes are. You said you didn’t want to use interfaces; well, I can’t think of a way around that. You may have to bite the bullet or do some code duplication.

    At minimal, you can move the behaviour logic to a separate controlling class and simply feed it some interface that exposes the members needed. Consider the few properties you need for a scrollable UI control (mind you, this is all just whipped off examples, I doubt these types exist as I describe, or these are the actual minimum set needed):

    public interface ISCrollable
    {
        Control Target { get; }
        ScrollBar Bar { get; }
        double FullLength { get; }
        double VisibleLength { get; }
    }
    

    You then can put your scrolling behaviour in a class that attaches that behaviour or works upon an IScrollable:

    public class Scroller
    {
        public Scroller(ISCrollable scrollable)
        {
            //attach behaviour
            scrollable.Bar.OnClick += DoScroll;
            //and other stuff
        }
    }
    

    Finally, your ScrollableWidget would be your Control and attach the scrolling behaviour rather than inheriting it:

    public class ScrollableWidget : Control, INamingContainer, ISCrollable, IWidget
    {
        private Scroller ScrollBehaviour;
        private Widgeter = WidgetBehaviour;
    
        public Control Target { get; private set; }
        public ScrollBar Bar { get; private set; }
        public double FullLength { get; private set; }
        public double VisibleLength { get; private set; }
    
        public ScrollableWidget()
        {
            this.Target = this;
            this.Bar = CreateScrollBarControl();
            this.FullLength = 9001;
            this.VisibleLength = this.ActualHeight;
    
            this.ScrollBehaviour = new Scroller(this);
            this.WidgetBehaviour = new Widgeter(this);
        }
    }
    

    So yeah, you’re going to want to use interfaces. I don’t understand your requirement not to. There are other patterns, such as Decorator, that may be a better suit than the mess I just posted.

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

Sidebar

Related Questions

I have an abstract entity base class defined like this: public abstract class SessionItem
I have an abstract method in a base class declared like so... public abstract
I have an abstract base class and an implementation class like: public abstract class
I have one base class which holds a map for function pointers like this
I have an abstract base class called Shape from which both Circle and Rectangle
I have an abstract base class called Party. There are several concrete subclasses (Company,
I have an abstract base class class AbstractClass { Col<AbstractClass> parent public AbstractClass() {
I have an abstract base class that holds a Dictionary. I'd like inherited classes
I have two classes (MVC view model) which inherits from one abstract base class.
I have an Abstract class called Function which has 2 inheriting classes (actually 6,

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.