在 C++/C# 中,私有类变量的常见约定是m_MyPrivateVar
,并且我相信“m_” 代表“我的”(我可能是错的)。
在 Delphi 中,私有类变量以F,例如F手柄等
F 是什么意思?福? :)
有一些命名约定,以免在代码中迷失。
这是一个例子来指出为什么这很有用。
// Types begins with T
TFoo = class
strict private
// sometimes I saw strict private fields beginning with underscore
// I like this too
_Value : string;
private
// private class vars are Fields and therefore begins with F
FValue : string;
function GetValue : string;
public
property Value : string read GetValue write FValue;
// Parameters should NOT begin with P (P is for Pointer) but with A
// because "i will pass A value" :o)
function GetSomething( const AValue : string ) : string;
end;
function TFoo.GetValue : string;
begin
Result := '*' + FValue + '*';
end;
function TFoo.GetSomething( const AValue : string ) : string;
var
// IMHO there is no naming convention to Local vars
// but mine begins with L
LValue : string;
begin
LValue { local var } :=
Value { property via getter } +
AValue { parameter } +
FValue { field };
Result := LValue;
end;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)