在学习编程之前,我学过Pascal语言的结构化编程,现在开始学习Delphi中的面向对象编程。
因此,我不太理解strict private
指令和protected
指令之间的区别。这是我的代码,它是关于创建“包裹”的,只是我的Delphi课程介绍的一部分,老师向我们展示了如何创建对象:
uses
SysUtils;
Type
Tbag= class (Tobject)
strict private
FcontenM : single;
Fcontent : single;
protected
function getisempty : boolean;
function getisfull: boolean;
public
constructor creer (nbliters : single);
procedure add (nbliters : single);
procedure clear (nbliters : single);
property contenM : single read FcontenM;
property content : single read Fcontent;
property isempty : boolean read getisempty;
property isfull : boolean read getisfull;
end;
function Tseau.getisempty;
begin
result := Fcontent = 0;
end;
function Tseau.getisfull;
begin
result := Fcontent = FcontenM;
end;
constructor Tseau.creer(nbliters: Single);
begin
inherited create;
FcontenM := nbliters;
end;
procedure Tbag.add (nbliters: Single);
begin
if ((FcontenM - Fcontent) < nbliters) then fcontent := fcontenM
else Fcontent := (Fcontent + nbliters);
end;
procedure Tbag.clear (nbliters: Single);
begin
if (Fcontent > nbliters) then Fcontent := (Fcontent - nbliters)
else Fcontent := 0;
end;
那么这只是一个对象创建的示例;我理解什么是公共声明(可以被外部访问的接口),但我不明白私有和受保护声明之间的区别...感谢您试图帮助我。