I have been writing different classes lately, and I have noticed that I have inadvertently been reading / writing to them using both field
and property
identifiers, and I am wondering what are the pitfalls if any of doing this?
Lets use a basic class as an example:
TMyClass = class
private
FName: string;
FID: Integer;
public
constructor Create(AName: string);
destructor Destroy; override;
published
property Name: string read FName write FName;
property ID: Integer read FID write FID;
end;
By field
identifier I mean, for example FName
and FID
, and by property
identifier I mean Name
and ID
for example.
The whole purpose of the published property
is to be able to access it outside of the unit the class is written in if I am not mistaken. Which surely means the field
identifiers should be used in the unit the class is written in, after all you cannot access those field
identifiers outside the class.
This is where I have noticed that in some of the procedures (private or protected) I have not been using FName
or FID
, but instead have used the property
equivalent, Name
and ID
- or sometimes mixed.
So far I have seen no issues, and in fact I normally would use FName
and FID
but like I say, have inadvertently not done so for some reason.
Is this bad practice or could it lead to something more sinister?
Thanks.