Search the Community
Showing results for tags 'inheritance'.
Found 2 results
-
i have base interface: type iBaseFoo = interface BaseMethod1; BaseMethod2; BaseMethod3; end; iTestFoo = interface(ibaseFoo) TestFooMethod; end; -- TBaseFoo = class(TInterfacedObject, iBaseFoo) private // some code here protected BaseMethod1; BaseMethod2; BaseMethod3; end; TTestFoo = class(TBaseFoo, ITestFoo) // how to Ensures TTestFoo inherits IBaseFoo methods from TBaseFoo, avoiding re-implementation. procedure TestFooMethod; end; -- my question is: How can I ensure that TTestFoo (or any descendant of TBaseFoo) uses the IBaseFoo method implementations provided by TBaseFoo, without re-implementing these methods in every descendant class?
- 14 replies
-
- code reuse
- class hierarchy
- (and 3 more)
-
Hi Delphi addicts, I want to create an "inherited class property". - I define a class property in Master - Define a local getter in Master, because a getter must be static - Define an abstract class procedure, called by the getter - Implement the class procedure in Child Writing it in Delphi and compiling it, all goes well. When executing the code, the getter raises an abstract error when calling the class procedure. What am I missing? Is there a way to define inheritable polymorf class properties? unit Unit1; interface type TMaster = class private class function GetMasterId: integer; static; {MUST be a static method for a property getter} protected class function GetChildID: integer; virtual; abstract; public class property id: integer read GetMasterId ; end; TChild = class(TMaster) protected class function GetChildID: integer; override; end; implementation { TMaster } class function TMaster.GetMasterId: integer; begin result := GetChildID ; { <= at this point I get an abstract error} end; { TChild } class function TChild.GetChildID: integer; begin result := 1 end; end. procedure TForm2.Button1Click(Sender: TObject); begin Edit1.Text := inttostr(TChild.id) { <= Calling the Child's property} end;
- 8 replies
-
- class method
- polyformism
-
(and 1 more)
Tagged with: