okok... das Beispiel war wohl zu minimiert.
Delphi-Quellcode:
unit Base;
interface
type
Visitor =
class;
Base =
class
public
procedure Accept(v : Visitor);
virtual;
abstract;
end;
A =
class(Base)
public
procedure Accept(v : Visitor);
override;
function AZeugs() :
String;
end;
B =
class(Base)
public
procedure Accept(v : Visitor);
override;
function BZeugs() :
String;
end;
Visitor =
class
public
procedure Visit(a : A);
overload;
procedure Visit(b : B);
overload;
end;
implementation
{ Visitor }
procedure Visitor.Visit(a: A);
begin
WriteLn(a.AZeugs());
end;
procedure Visitor.Visit(b: B);
begin
WriteLn(b.BZeugs());
end;
//...
end.