I need to use an external library which has a class hierarchy, TC1 base, TC2 which derives from TC1, TC3A and TC3B which derive from TC2. I need to extend each class of this hierarchy with some attributes and methods, which will obviously need to be inherited from the derived classes. I don't want to change the library code. I can't use class helpers because I also have attributes to add. And Delphi doesn't support multiple inheritance. The use of encapsulation instead of inheritance seems to me not applicable in this case. How can I solve the problem?
Asked
Active
Viewed 211 times
0
-
In Delphi multiple inheritance is possible through using interfaces. Whether or not that approach fits to your use case and how to achieve it is impossible to say without some minimal basic code [mcve] and more detailed explanation of your problem. – Dalija Prasnikar Jan 21 '21 at 10:43
-
Maybe the visitor design pattern can help you? – Delphi Coder Jan 21 '21 at 12:36
-
Interfaces also support properties, but you need to provide getter and setter methods. Still, without having any idea about your code it is impossible to give you any more detailed and more suitable answers. Please edit your question and provide more information. – Dalija Prasnikar Jan 21 '21 at 15:03
-
Interfaces allow methods only. I want to extend fields too. – simone Jan 21 '21 at 15:10
-
1You can't add fields without changing the class definition (or one of its ancestors). – Olivier Jan 21 '21 at 15:28
-
I'm using SimpleGraph component (http://www.delphiarea.com/products/delphi-components/simplegraph/). In its code there are TGraphObject as the base class, TGraphNode and TGraphLink deriving from it, as well as TRectangularNode, TEllipticNode, etc deriving from TGraphNode. I need to extend TGraphObject with fields and methods that need to be inherited byTGraphNode and TGraphLink. Moreover I want to extend TGraphNode in turn with fields and methods that need to be inherited by TRectangularNode, TEllipticNode. – simone Jan 21 '21 at 15:31
-
The question for us is, why you want to do this? And what you want to add specifically? The more context you give you more likely get some help here. – Delphi Coder Jan 21 '21 at 20:16