しかし、私はプログラミングを学び、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;
したがって、これはオブジェクト作成の単なる例です。public 宣言 (外部からアクセス可能なインターフェイス) とは何かを理解していますが、private 宣言と protected 宣言の違いがわかりません..私を助けてくれてありがとう..