IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
To/From Code
-Collapse +Expand Cross Ref Guide
-Collapse +Expand Members-Only
Sign in to see member-only pages.
   ► KBTo/From GuidesC#  Print This     

Member Visibility (C# and Delphi Cross Reference Guide)

By Mike Prestwood

C# versus Delphi: A side by side comparison between C# and Delphi.

 
OOP Basics
 

Some languages support object-based concepts such as Paradox, Access, and VB Classic. Other languages have OO extensions and fully support object orientation in a hybrid fashion (such as C++ and Dephi for Win32). Finally, some lanages such as C#, VB.Net, Prism, and Java are entirely written in OO. Meaning, every line of code written must occur within a class).

Member Visibility

[Other Languages] 

General Info: Class Visibility Specifiers

In OOP languages, members of a class have a specific scope that indicates visibility. Standard visibility includes private, protected, and public. Private members are usable by the defining class only (fully encapsulated). They are invisible outside of the class except by friendly classes. Protected members are usable by the defining class and descendant classes only (plus friendly classes). Public members are usable wherever its class can be referenced.

Languages Focus

Traditional member visibility specifiers for fully OOP languages are private, protected, and public. Many modern OOP languages implement additional member visibilities.

Additional member modifiers are documented under the Member Modifiers topic.

C#:  "Access Modifiers"

In C#, you specify each class and each class member's visibility with an access modifier. The C# access modifiers are the traditional public, protected, and private plus the two additional .Net modifiers internal and protected internal.

Internal indicates members are accessible from types in the same assembly. Protected internal indicates members are accessible from types in the same assembly as well as descendant classes. OO purist might object to internal and protected internal and I suggest you choose private, protected, or public over them until you both fully understand them and have a need that is best suited by them.

Syntax Example:
public class Cyborg
{
private String FName;
}
Delphi: 

In Delphi, you group member declarations as part of defining the interface for a class in the Interface section of a unit.

Up until D2005, private and protected were not implemented strictly. Starting with D2005, a traditional strict versions of OOP are supported using the strict keyword. OO purist will want you to use strict private over private and strict protected over protected. I suggest you follow that advice until you both fully understand the differences and have a specific need.

Delphi offers a special published specifier which is the same as public members but runtime type information (RTTI) is generated.

Syntax Example:
TCyborg = class(System.Object)
private
//Don't use accept when you really want private friendly members.
strict private
//Use as your default private members.
  FName: String;
protected
//Don't use accept when you really want protected friendly members.
strict protected
//Use as your default protected members.
public
  

published
  //RTTI Info

end;












Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site: 
www.prestwood.com


©1995-2024 Prestwood IT Solutions.   [Security & Privacy]