추상·봉인 객체

추상·봉인 객체 (Abstract and Sealed Objects)

객체를 sealed로 선언할 수 있어요. 그러면 그 객체의 자손(descendent) 객체를 선언할 수 없게 됩니다. 컴파일러는 자손 선언을 만나면 오류를 돌려줘요.

출처: Abstract and sealed objects

본문

Type
  TMyClass = object Sealed
    x : integer;
  end;

  TMyClass2 = object(TMyClass)
    Y : Integer;
  end;

begin
end.

이 코드는 다음과 같은 오류를 냅니다.

Error: Cannot create a descendant of the sealed class "TMyClass"

추상(abstract) 클래스는 직접 사용할 수 없는 클래스예요. 대신 항상 자손 클래스를 사용해야 합니다. 다만 Delphi 호환을 위해 컴파일러는 이 지시어를 무시해요.

더 알아보기