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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:52:33+00:00 2026-05-13T09:52:33+00:00

I’m writing a plug-in for a 3D modeling program. I have a custom class

  • 0

I’m writing a plug-in for a 3D modeling program. I have a custom class that wraps instances of elements in the 3D model, and in turn derives it’s properties from the element it wraps. When the element in the model changes I want my class(es) to update their properties based on the new geometry.

In the simplified example below. I have classes AbsCurveBasd, Extrusion, and Shell which are all derived from one another. Each of these classes implement a RefreshFromBaseShape() method which updates specific properties based on the current baseShape the class is wrapping.

I can call base.RefreshFromBaseShape() in each implementation of RefreshFromBaseShape() to ensure that all the properties are updated. But I’m wondering if there is a better way where I don’t have to remember to do this in every implementation of RefershFromBaseShape()? For example because AbsCurveBased does not have a parameterless constructor the code wont even compile unless the constructors call the base class constructors.

public abstract class AbsCurveBased
{
    internal Curve baseShape;
    double Area{get;set;}

    public AbsCurveBased(Curve baseShape)
    {
        this.baseShape = baseShape;
        RefreshFromBaseShape();
    }

    public virtual void RefreshFromBaseShape()
    {
        //sets the Area property from the baseShape
    }
}


public class Extrusion : AbsCurveBased
{
    double Volume{get;set;}
    double Height{get;set;}

    public Extrusion(Curve baseShape):base(baseShape)
    {
        this.baseShape = baseShape;
        RefreshFromBaseShape();
    }

    public override void RefreshFromBaseShape()
    {
        base.RefreshFromBaseShape();
        //sets the Volume property based on the area and the height
    }
}


public class Shell : Extrusion
{
    double ShellVolume{get;set;}
    double ShellThickness{get;set;}

    public Shell(Curve baseShape): base(baseShape)
    {
        this.baseShape = baseShape;
        RefreshFromBaseShape();
    }

    public void RefreshFromBaseShape()
    {
        base.RefreshFromBaseShape();
        //sets this Shell Volume from the Extrusion properties and ShellThickness property
    }
}
  • 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-13T09:52:33+00:00Added an answer on May 13, 2026 at 9:52 am

    The way you do it is a very typical pattern, and there’s certainly nothing wrong with it – it’s how such a thing is usually done. There’s no way to force that base call, on presumption that when and where it happens is always up to the implementer. If you are really keen on forcing it, then you should consider using a protected event instead:

    public abstract class AbsCurveBased
    {
        internal Curve baseShape;
        double Area{get;set;}
    
        public AbsCurveBased(Curve baseShape)
        {
            this.baseShape = baseShape;
            RefreshFromBaseShape();
        }
    
        public void RefreshFromBaseShape()
        {
            //sets the Area property from the baseShape
            ...
    
            // call child handlers
            var handler = RefreshingFromBaseShape;
            if (handler != null)
                handler();
        }
    
        protected event Action RefreshingFromBaseShape;
    }
    
    public class Shell : Extrusion
    {
        double ShellVolume{get;set;}
        double ShellThickness{get;set;}
    
        public Shell(Curve baseShape): base(baseShape)
        {
            this.RefreshingFromBaseShape += RefreshingFromBaseShapeHandler;
    
            this.baseShape = baseShape;
            RefreshFromBaseShape();
        }
    
        private void RefreshingFromBaseShapeHandler()
        {
            //sets this Shell Volume from the Extrusion properties and ShellThickness property
        }
    }
    

    That way any class in the inheritance chain only has control over its handler(s), and cannot unregister the handlers of his ancestors, or insert them into the chain before the ancestors insert theirs.

    For your particular case, though, this seems like too much complexity for no worth.

    Also, if RefreshFromBaseShape is only ever called from constructor, then perhaps it should rather be a parameter of that constructor. Consider:

    public abstract class AbsCurveBased
    {
        internal Curve baseShape;
        double Area{get;set;}
    
        public AbsCurveBased(Curve baseShape)
        {
            this.baseShape = baseShape;
    
            //sets the Area property from the baseShape
        }
    
        protected AbsCurveBased(Curve baseShape, Action refreshFromBaseShape):
            this(baseShape)
        {
            refreshFromBaseShape();
        }
    }
    
    public class Shell : Extrusion
    {
        double ShellVolume{get;set;}
        double ShellThickness{get;set;}
    
        public Shell(Curve baseShape):
            base(baseShape, RefreshFromBaseShape)
        {
        }
    
        protected Shell(Curve baseShape, Action refreshFromBaseShape):
            this(baseShape)
        {
            refreshFromBaseShape();
        }
    
        private void RefreshFromBaseShape()
        {
            //sets this Shell Volume from the Extrusion properties and ShellThickness property
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 304k
  • Answers 304k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You should return an appropriate status code. 404 means that… May 13, 2026 at 8:48 pm
  • Editorial Team
    Editorial Team added an answer $("#existingUserForm :input[name='userPassword'], #existingUserForm :input[name='userName'] ").keypress( function(e) { if(e.which == 13)… May 13, 2026 at 8:48 pm
  • Editorial Team
    Editorial Team added an answer I'm assuming that this is homework. How is the loop… May 13, 2026 at 8:48 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want use html5's new tag to play a wav file (currently only supported
I've got a string that has curly quotes in it. I'd like to replace
In order to apply a triggered animation to all ToolTip s in my app,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.