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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:10:36+00:00 2026-05-23T08:10:36+00:00

Possibly bad practice but I’m not well versed in software design anyway (I’m sure

  • 0

Possibly bad practice but I’m not well versed in software design anyway (I’m sure this question would have been asked before but I can’t seem to find the right terminology)…Anyhow, it’s just another curiosity of mine I’d like to have answered.

So I have worked in a way where I type a base class variable to type Object or Sprite or something similar so that in my subclasses, I can instantiate my custom classes into them and store it. And when I access it, I just cast that variable to ensure I can access the methods.

Take this example, so that you know what I’m talking about:

public class BaseClass
{
  protected var the_holder_var:Object;

  public function BaseClass()
  {
    //Whatever abstract implementation here...
  }
}

Now, my subclasses of that base class usually use an interface but for simplicity sake, I’ll just write it without it.

public class AnExtendedClass extends BaseClass
{
  public function AnExtendedClass()
  {
    //Instantiate my own class into the base class variable
    this.the_holder_var = new ACustomClassOfMine(); 

    //Then I can use the 'hackish' getter function below to 
    //access the var's functions.
    this.holder_var.somefunction()
  }

  private function get holder_var():ACustomClassOfMine
  {
    return this.the_holder_var as ACustomClassOfMine;
  }
}

This works and I’m sure it will make some ppl cringe (I sometimes cringe at it too).
So now, my question, is there a way to recast/retype that base var in my extended subclass?

kinda like this:

public class ExtendedClass extends BaseClass
{
  //Not possible I know, but as a reference to see what I'm asking about
  //Just want to change the type....
  override protected var the_holder_var:ACustomClassOfMine;

  public function ExtendedClass()
  {
    //Then I can forget about having that hackish getter method.
    this.the_holder_var = new ACustomClassOfMine();
    this.the_holder_var.somefunction();
  }
}

I was thinking of typing most of my base class vars that I use as holders as type * and retyping them as I extend the class. (I could use it here too but yeah…)
Thoughts? Comments? Ideas?

  • 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-23T08:10:37+00:00Added an answer on May 23, 2026 at 8:10 am

    I actually think your code (apart from the hypothetical addition at the end) is pretty alright. The practise of adding accessors to solve the type issue you’re dealing with is a solid one. I would advise to rename the accessor to show it is a cast, maybe get holderVarAsCustom():ACustomClassOfMine (I’m also not a big fan of the underscores, that’s another language’s convention), but that’s personal preference. What I’d do to solve your last problem is just create a matching setter function:

    private function set holderVarAsCustom(value:ACustomClassOfMine):void {
      this.the_holder_var = value;
    }
    

    This way you can access the correctly typed holder var for both read and write operations with complete type safety:

    holderVarAsCustom = new ACustomClassOfMine();
    holderVarAsCustom.someFunction();
    

    I would definately advise against dropping the type safety by including arrays and what not, that just makes it unstable.

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

Sidebar

Related Questions

I realize that this would be COMPLETELY bad practice in normal situations, but this
Maybe I'm having a really bad day, but could someone possibly help me to
Possibly a silly question, but I'm having no luck finding an answer. Using Visual
This is possibly very lame question and I lack knowledge about ASP.Net. In this
Before you ask... I don't plan to actually do this. It's bad practice for
I know this is bad practice. Don't write code like this if at all
I know they are bad practice but I have a real need on an
Possible Duplicate: Are iframes considered 'bad practice'? Some say that iFrame is evil. But
Possible Duplicate: Are iframes considered 'bad practice'? While working with web developers, I always
Possible Duplicate: What is so bad about Singletons? It's understandable that many design patterns

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.