但是我学习了编程,在使用 Pascal 语言进行结构化编程之后,我开始使用 Delphi 学习 OOP。
所以,我不太明白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;
所以这只是对象创建的一个例子;我了解什么是公共声明(外部可访问的界面),但我看不出私有声明和受保护声明之间有什么区别。感谢您尝试帮助我。