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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:22:34+00:00 2026-05-16T20:22:34+00:00

Like a lot of C# programmers, I eventually found myself in need of what

  • 0

Like a lot of C# programmers, I eventually found myself in need of what would essentially be static abstract method functionality. I’m fully aware of why it can’t be done, and it makes sense, but I’m in need of a workaround.

I’m working on an XNA game, but the problem doesn’t involve too much XNA code, fortunately. I have an abstract base class Note, and various subclasses derived from it. At a certain point, I’ll be drawing these to the screen, so I’ll have to load textures (each subclass would have different textures and different amounts of textures), have the user input a size parameter, scale the textures to size, and then iterate over my List and Draw() each one. These textures are pretty large, and each instance of a given subclass would be using the same textures at the same scaled size until the user specifies a different size, hence my motivation for taking a static approach.

As I’ve found out, abstract static methods aren’t available. I would have liked to been able to do a single texture resize at a time (whenever the user changed the size parameter) for each subclass, save the scaled texture as a static Texture2D object, and just reference each time I would draw an instance of the Note subtype. That way I could have avoided having a Texture2D object in every instance of a given Note-derived class, as well as having to scale the Texture2D in each instance as well. In addition, I would have liked being able to effectively enforce “all concrete subclasses of Note must implement this static method”.

I’m not exactly sure what would be the best approach. I’d prefer a way to do that didn’t involve needing to have a static method in each subclass, e.g.:

NoteA.LoadScaledTex(scale);
NoteB.LoadScaledTex(scale);
NoteC.LoadScaledTex(scale);
...
foreach(Note n in notes) {..}

but I’m not sure of any other elegant solution.

  • 1 1 Answer
  • 4 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-16T20:22:35+00:00Added an answer on May 16, 2026 at 8:22 pm

    Static actually isn’t really appropriate simply because a given piece of data should be shared across all instances of a particular type. Rather (and in this case especially) you should use a singleton, where all instances internally refer to the same, single instance to store shared data. This way you can easily override the implementation at various inheritance levels, and even gives you the flexibility to have some derived types not even use the singleton.

    public abstract class Note
    {
        public abstract void LoadScaledTex(scale);
    }
    
    public class NoteA : Note
    {
        private static ScaledTexData instance;
    
        public override void LoadScaledTex(scale)
        {
            lock(this.GetType())
            {
                if(instance == null)
                {
                    instance = new ScaledTexData(scale);
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I like these a lot, and would like to use them for everything. Why
all experienced programmers. I need advice on following. What would be the best practice
It seems like a lot of people here and on many programmer wikis/blogs/ect. elsewhere
So it seems like a lot of people are playing the blame game around
Okay guess this question looks a lot like: What is the best way to
An export of the Eclipse preferences looks a lot like a Properties file. Is
I'm trying to re-use a Java generic collection I wrote, looks a lot like
I like vectors a lot. They're nifty and fast. But I know this thing
if i like Ruby a lot, is there a reason I should learn another
I stumbled over node.js sometime ago and like it a lot. But soon I

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.