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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:48:25+00:00 2026-05-16T02:48:25+00:00

Is it possible to do something like the following: public class ChildClass : BaseClass

  • 0

Is it possible to do something like the following:

public class ChildClass : BaseClass
{
    public ChildClass(BaseClass o)
    {
        base = o;
    }
}

Basically, I want a transparent way to wrap a base class inside of other functionality. One example I’ve thought of is a custom Settings Provider which transparently audits the settings passed through it.

public class SettingsAuditor : SettingsProvider
{
    public SettingsAuditor(SettingsProvider o)
    {
        base = o;
    }

    public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection propvals)
    {
        // Log the property change to a file
        base.SetPropertyValues(context, propvals);
    }
}

Then I could do the following:

mySettingsProvider = new SettingsAuditor(mySettingsProvider);

And all changes would go through the overridden SetPropertyValues before passing to the original object.

I could use a private SettingsProvider member, but then I either cannot inherit from SettingsProvider, or have an entire SettingsProvider (base) not being used at all.

I’m using C# 4.0 and .Net 4.0.

  • 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-16T02:48:26+00:00Added an answer on May 16, 2026 at 2:48 am
    1. You cannot do base = o;
    2. What you’re looking for is the Decorator Pattern), which is a way to compositionally add functionality at runtime (vs. inheritance).

    Instead of trying to set the base, you just contain the inner member. As long as the wrapper implements the same interface or base class as the inner object, you can pass back the new wrapper. You can wrap as many decorators as you want.

    Consider:

    public interface ICar
    {
        void Drive();
    }
    
    public class Car : ICar
    {
        public void Drive()
        {
            Console.WriteLine("vroom");
        }
    }
    
    public class BuckleUp : ICar
    {
        ICar car;
    
        public BuckleUp(ICar car) { this.car = car; }
    
        public void Drive()
        {
            Console.WriteLine("click!");
            car.Drive();
        }
    }
    
    public class CheckMirrors : ICar
    {
        ICar car;
        public CheckMirrors(ICar car) { this.car = car; }
    
        public void Drive()
        {
            Console.WriteLine("mirrors adjusted");
            car.Drive();
        }
    }
    

    Now consider you have a method that accepts an ICar and tells it to drive. You could give it a Car, and it would work, but you could also wrap that car in a BuckleUp and a CheckMirrors and you wouldn’t have to change that method at all. You’ve modified functionality through composition using the Decorator Pattern.

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

Sidebar

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.