![]() |
AW: Was sind Interfaces und wie wendet man sie an? (brauche tut)
Ein entschiedener Unterschied ist, dass eine Klasse mehrere Interfaces implementieren kann, aber nicht von mehreren Klassen erben kann.
Das funktioniert nicht
Delphi-Quellcode:
aber mit Interfaces geht es
type
TEsel = class abstract end; THund = class abstract end; TKatze = class abstract end; THahn = class abstract end; TBremerStadtmusikanten = class( TEsel, THund, TKatze, THahn ) // das geht nicht! end;
Delphi-Quellcode:
type
IEsel = interface end; IHund = interface end; IKatze = interface end; IHahn = interface end; TBremerStadtmusikanten = class( TInterfacedObject, IEsel, IHund, IKatze, IHahn ) end; |
AW: Was sind Interfaces und wie wendet man sie an? (brauche tut)
Aber sind die Bremerstadtmusikanten nicht eher ein Stack? :mrgreen:
|
AW: Was sind Interfaces und wie wendet man sie an? (brauche tut)
Zitat:
Zitat:
Aber ich verstehe nicht, was du mit unsichtbar meinst. Zitat:
Standardmässig gelten die Modifizierer aber nicht innerhalb der Unit, höchstens du deklarierst sie als strict. |
AW: Was sind Interfaces und wie wendet man sie an? (brauche tut)
Zitat:
|
AW: Was sind Interfaces und wie wendet man sie an? (brauche tut)
Zitat:
|
AW: Was sind Interfaces und wie wendet man sie an? (brauche tut)
Zitat:
|
AW: Was sind Interfaces und wie wendet man sie an? (brauche tut)
Zitat:
Zitat:
Delphi-Quellcode:
Hier sind die Klassen 'TClass1' und 'TClass2' unsichtbar.
Unit myAssembly;
interface Type IMyInterface = interface... IInterface1 = interface (IMyInterface)... IInterface2 = interface (IMyInterface) function Factory<T : IMyInterface>() : T; // geht das? implementation Type TClass1 : class (TInterfacedObject, IInterface1) end; TClass2 : class (TInterfacedObject, IInterface2) end; ... end. Zitat:
|
AW: Was sind Interfaces und wie wendet man sie an? (brauche tut)
@Dejan Vu
Ja, das geht so mit den Factories (allerdings nicht mit den Generics in einer simplen Funktion) |
AW: Was sind Interfaces und wie wendet man sie an? (brauche tut)
Zitat:
Delphi-Quellcode:
TLogger = class()
--- end; TPerson = class(TLogger) --- |
Alle Zeitangaben in WEZ +1. Es ist jetzt 22:44 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz