AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren

3 Fragen zu Interfaces in Delphi.Net

Offene Frage von "winx"
Ein Thema von winx · begonnen am 30. Mär 2006 · letzter Beitrag vom 30. Mär 2006
Antwort Antwort
jenbru

Registriert seit: 23. Dez 2005
5 Beiträge
 
Delphi 7 Professional
 
#1

Re: 3 Fragen zu Interfaces in Delphi.Net

  Alt 30. Mär 2006, 10:17
Hallo,

Zitat von winx:
1. Wie kann ich in Delphi.Net ein Interface implementieren?
2. Kann ich auch mehrere Interfaces implementieren?
3. Wie "vererbt" man Interfaces
Bsp: Interface A ist eine Spezialisierung von B und B wiederum von C... schreibt man
da in A wieder alle Funktionen von B rein oder implementiert A einfach B???
zu 1)
Das ist eigentlich ganz einfach:

Delphi-Quellcode:
//Ein Interface
type
  IAnInterface = interface
    procedure AMethod;
  end;

//Eine mögliche Implementierung
type
 TAnImplementation = class(TObject, IAnInterface)
   procedure AMethod;
 end;
zu 2)
Natürlich:

Delphi-Quellcode:
//Noch ein Interface
type
  IAnotherInterface = interface
    procedure AnotherMethod;
  end;

//Klasse implementiert jetzt beide Interfaces
type
 TAnImplementation = class(TObject, IAnInterface, IAnotherInterface)
   procedure AMethod;
   procedure AnotherMethod;
 end;
zu 3)
Weder noch.
Ein Interface erbt wie eine Klasse alle Methoden vom Vorfahr-Interface. Der Vorfahr alle Interfaces in Delphi ist IInterface.
Ein Interface ist somit verpflichtet alle Methoden des Vorfahr-Interfaces zu implementieren. Das es das selbst aber nicht kann
geht die Verpflichtung auf die Klasse über, die eine Implementierung des Interface anbietet:


Delphi-Quellcode:
type
  IC = interface
    procedure C;
  end;

type
  IB = interface(IC)
    procedure B;
  end;

type
  IA = interface(IB)
    procedure A;
  end;

type
  TImpl = class(TObject, IA)
    procedure A;
    procedure B;
    procedure C;
  end;
Das steht aber auch alles in der OH von D2005 im Kapitel "Objekt-Interfaces".

Schönen Gruß,
Jens
Jens Brünnler
  Mit Zitat antworten Zitat
Antwort Antwort

Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 19:36 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