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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:26:26+00:00 2026-05-26T19:26:26+00:00

So I have this system set up with a base class DisplayObject . It

  • 0

So I have this system set up with a base class DisplayObject.
It has a Render method and a list of other DisplayObjects as it’s children. It also contains data about various matrix transformations but I does not contain the data about the actual drawing. That’s why the Render method is virtual.

I then have 2 classes. ColoredShape and TexturedShape each inheriting from DisplayObject and overriding the Render method with a new method starting with

base.Render(); 

and then doing the drawing code.

What I want now is to call Render on all of the object’s children after the Render on the parent has finished. So there’s my problem. If I do

foreach (var child in Children) child.Render();

at the end of the Render method in the DisplayObject class it will be executed before the overrides are, since it’s a part of the base.Render() call, and if I put that code in the subclasses instead, the DisplayObject alone loses that functionality and it forces all the future subclasses inheriting from it to implement the feature manually.

  • 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-26T19:26:27+00:00Added an answer on May 26, 2026 at 7:26 pm

    What you want is the abstract method pattern. In other words, don’t make your render method virtual crate another method (virtual or abstract) that render calls., so render will look something like this:

    public void Render()
    {
        DoRender()
    
        foreach (var child in _children)
        {
            child.Render();
        }
    }
    
    protected virtual void DoRender()
    {
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this class that contains vars for db connection; Imports Microsoft.VisualBasic Imports System.Data.SqlClient
This is more of a conceptual question than anything. I have a base class
I have usercontrols which inherit a base class which looks like this: BasePage.cs: using
I have this class: using System; using System.Collections.Generic; using System.Runtime.Serialization; namespace Grouping { [Serializable]
I have created a BasePage class that inherits from System.Web.Ui.Page. In that base class
I have a page base class (.NET4): public class SitePageBase : System.Web.UI.Page { protected
I have a repository pattern setup using NHibernate. The base class looks like this:
The base class WebPart has a property defined like this: [WebBrowsable(true)] public virtual string
I have a base class like this class Base { public var space:Number; }
I have this code :- using (System.Security.Cryptography.SHA256 sha2 = new System.Security.Cryptography.SHA256Managed()) { .. }

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.