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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:39:26+00:00 2026-06-13T08:39:26+00:00

I have an abstract class and I’d like to initialize a readonly field in

  • 0

I have an abstract class and I’d like to initialize a readonly field in its protected constructor. I’d like this readonly field to be available in derived classes.

Following my habit of making all fields private and exposing properties, I implemented this as follows:

abstract class Foo
{
    private readonly int _field;

    protected Foo(int field)
    {
        _field = field;
    }

    protected int Field
    {
        get { return _field; }
    }
}

But then I wondered if there is really much advantage of keeping the field private here. I’m aware of the advantages of properties and there are several SO questions on this issue in general, but they focus on public fields as opposed to protected ones.

So should I switch to the below implementation or not? What are the considerations and advantages/disadvantages to be aware of in either case?

abstract class Foo
{
    protected readonly int _field;

    protected Foo(int field)
    {
        _field = field;
    }
}
  • 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-06-13T08:39:27+00:00Added an answer on June 13, 2026 at 8:39 am

    Derived classes are still ‘users’ of the original code; fields should be encapsulated from them too.

    You should think of base classes as safe and extendable APIs, rather than just classes which expose their internals. Keep the fields private – apart from anything, it allows the base class to change how that property’s value is generated 🙂

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

Sidebar

Related Questions

I have an abstract base class from which many classes are derived. I want
I have an abstract class Camera. There are some derived classes that will handle
I have an abstract class like this public abstract class Abstractclass { public Abstractclass(int
Let say I have abstract class called: Tenant and Customer. The tenant in this
I have abstract BaseController, which basically looks like below: public abstract class BaseController :
I have an abstract class that implements IDisposable, like so: public abstract class ConnectionAccessor
I have one abstract class -let's say myBase. And I want all the classes
I have one abstract class and many child classes. In child classes are from
I have an abstract base Controller class and all action controllers are derived from
If I have abstract class Base<TSub> { protected static List<TSub> MyStaticList; } class DerivedA

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.