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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:56:53+00:00 2026-05-28T14:56:53+00:00

Code example: unit Foo; TFoo = class protected FList: TList; // Lifetime is managed

  • 0

Code example:

unit Foo;

  TFoo = class
  protected
    FList: TList; // Lifetime is managed by constructor and destructor
  public
    property List: TList read FList;
    constructor Create;
    destructor Destroy; override;
  end;

unit Bar;

  TBar = class(TFoo)
    procedure MyMethod;
  end;

procedure TBar.MyMethod;
begin
  // Access of FList goes here
end;

The TBar class is able to directly modify the value of FList, but that’s not strictly necessary, because it only has to call its methods / use its properties.

Should I make FList private and use the property to access it from TBar instead?

How do you handle cases like that? Are there any performance considerations as well?

  • 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-28T14:56:54+00:00Added an answer on May 28, 2026 at 2:56 pm

    While I agree that you could start out with the least privilege, and move things up in visibility when needed, it’s only because it ends up producing proper object oriented design without having to think too hard about whether the class member is a real business function that should be exposed.

    You should encapsulate and hide as much of the complexity as possible within an object so that the external interface is as minimalist as possible. One way to accomplish this is to only add or expose properties as you need them.

    If you don’t need external access to a particular member of the class, it’s probably simply an implementation artifact, and doesn’t fit the actual business use of the class. It’s complexity should, therefore, be hidden.

    In this case, because TBar inherits from TFoo, Protected is a valid visibility level, since it’s reserved for inherited classes. Also, because TBar is inherited from TFoo, maybe you’re thinking it should have some extra privileges to the inner workings of TFoo because it is, after all, its child class. Why should we relegate TBar to have the same low level of access as other classes?

    The answer depends on whether FList is an actual class member of TFoo, as we consider what the TFoo model represents, or whether it’s simply an implementation detail. Also, what is the level of access required? Are we simply accessing it, or are we changing the implementation?

    I’m guessing that you don’t need access to FList, and you’re not changing the implementation, in which case, even if the two classes were in the same unit, I would still make FList Private over Protected.

    If you were merely accessing the class member from descendant classes within the same unit, I would still keep it private.

    However, if FList were something that you need to override in TBar (probably not, since it’s not a method), or were designed as something that inherited classes should or would override, whether it was in the same unit or not, then you would want to make it Protected.

    You would also need to raise the visibility to Protected if you needed to access FList from descendant classes outside of the same unit.

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

Sidebar

Related Questions

How do you unit test code decorated with the PrincipalPermission attribute? For example, this
Is there anyway I can modify this code example #include <stdlib.h> #include <iostream> class
Take this code, for example: /* * foo.h * * Created on: Nov 5,
I am looking for example code that provides a unit test to serialize and
Is the following example a valid complete translation unit in C? struct foo; struct
Has any one some example code of mocking request.form in a unit test, calling
Code example: private void comboBox_SelectedIndexChanged(object sender, EventArgs e) { if(some condition) { comboBox.Text =
Consider following SWT code example: http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet151.java?view=co How can I separate the inline defined class?
In the following code example how do the user/userParam references relate to the Customer
There is an excellent code example on how to make nice jQuery Twitter style

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.