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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:55:14+00:00 2026-05-11T09:55:14+00:00

Here is something that I find myself using from time to time and I

  • 0

Here is something that I find myself using from time to time and I just wanted to get some feedback on the merits of the practice.

Lets say that I have a base class:

abstract class RealBase {     protected RealBase(object arg) {         Arg = arg;     }      public object Arg { get; private set; }      public abstract void DoThatThingYouDo(); } 

I often create a second base class that is generic that handles the cast from the ‘object’ type in the base class to the ‘T’ type, like this:

abstract class GenericBase<T> : RealBase {     protected GenericBase(T arg)         : base( arg ) {     }      new public T Arg { get { return (T) base.Arg; } } } 

This allows me to access ‘Arg’ as its explicit type without a cast operation:

class Concrete : GenericBase<string> {     public Concrete( string arg )         : base( arg ) {     }      public override void DoThatThingYouDo() {         // NOTE: Arg is type string. No cast necessary.         char[] chars = Arg.ToLowerInvariant().ToCharArray();           // Blah( blah, blah );         // [...]     }  } 

All the while being able to also work with it via the ‘RealBase’:

class Usage {     public void UseIt() {         RealBase rb = new Concrete( 'The String Arg' );         DoTheThing(rb);     }      private void DoTheThing(RealBase thingDoer) {         rb.DoThatThingYouDo();     } } 

It is assumed that there are many other ‘Concrete’ types… not just the one.

Here are my questions/concerns:

  1. Am I ‘off my rocker’ for using an approach like this?
  2. Are there any obvious drawbacks/caveats to using this approach?
  3. What about that ‘new public T…’ in GenericBase? Good/bad idea? Awkward?

Any feedback or advice would be greatly appreciated.

  • 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. 2026-05-11T09:55:14+00:00Added an answer on May 11, 2026 at 9:55 am

    I don’t have any objection to that explicitly as long as you’re disciplined enough to only use the generic base class as a helper only and never downcast to it. If you start referencing RealBase and GenericBase and ConcreteClass all over the place things tend to get real tightly coupled really quickly.

    As a matter of fact, I would recommend kicking it up a notch and introducing an interface

    interface IReal {   void DoThatThingYouDo(); } 

    And leaving the base class out of it entirely (basically never reference it except when declaring a derived class). Just a tip that helps me increase the flexibility of my code.

    Oh, and if you do use an interface, don’t just declare it in the base classes, declare it on the concrete ones:

    class MyConcrete: BaseClass<MyConcrete>, IReal {   ... } 

    as a reminder, the base class is not important only what it does is important!

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer You could use the MacroDef task to abstract the common… May 11, 2026 at 1:23 pm
  • added an answer Two things - one, you need semicolons after class declarations:… May 11, 2026 at 1:23 pm
  • added an answer When you are using forEach to create an integer loop,… May 11, 2026 at 1:23 pm

Related Questions

No related questions found

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.