Hi there,
Let's hope I can make myself clear:
I have a single interface that I want to implement in different classes. The implementations of the interface in the classes are almost the same, only a few of the METHODs differ.
What I would like to do is the following:
When I try this in PB/CC 5.01, I get the following error though:
Do I understand correctly that inheritance of an implementation is only possible when we create a new interface? That's not what I want (in this case).
The only solution I came up with is the following, but it's not really pretty IMHO, not to mention too much typing
:
Does anyone have any suggestions or know of a different solution that I missed?
Best regards, Vincent
Let's hope I can make myself clear:
I have a single interface that I want to implement in different classes. The implementations of the interface in the classes are almost the same, only a few of the METHODs differ.
What I would like to do is the following:
Code:
#COMPILE EXE #DIM ALL 'I usually "publish" Interfaces that I can use outside the current file in the program's header. '(this way I know which interfaces are supposed to be implemented by the 'program and which interfaces I only created for internal use) INTERFACE IncredibleInterface INHERIT CUSTOM METHOD AAA() METHOD BBB() METHOD CCC() END INTERFACE 'Here I create class CTest1 that has the "default implementation" of above's IncredibleInterface interface. CLASS CTest1 INTERFACE IncredibleInterface INHERIT CUSTOM METHOD AAA() ? "AAA1" END METHOD METHOD BBB() ? "BBB1" END METHOD METHOD CCC() ? "CCC1" END METHOD END INTERFACE END CLASS 'Now I want to create class CTest2, which implements the IncredibleInterface just like CTest1. 'I want to override 1 of the methods though, this is the only Method which has its own implementation. CLASS CTest2 INTERFACE IncredibleInterface INHERIT CTest1,IncredibleInterface OVERRIDE METHOD BBB() ? "BBB2" END METHOD END INTERFACE END CLASS FUNCTION PBMAIN () AS LONG DIM CT1 AS IncredibleInterface DIM CT2 AS IncredibleInterface CT1 = CLASS "CTest1" CT1.AAA CT1.BBB CT1.CCC CT2 = CLASS "CTest2" CT2.AAA CT2.BBB CT2.CCC CT1 = NOTHING CT2 = NOTHING WAITKEY$ END FUNCTION
PowerBASIC Console Compiler
PB/CC Version 5.01
Copyright (c) 1998-2009 PowerBasic Inc.
Venice, Florida USA
All Rights Reserved
Error 816 in C:\VDLTech\Berra\Tests\InheritTest2.bas(10:005): Internal system error
Line 10: END INTERFACE
PB/CC Version 5.01
Copyright (c) 1998-2009 PowerBasic Inc.
Venice, Florida USA
All Rights Reserved
Error 816 in C:\VDLTech\Berra\Tests\InheritTest2.bas(10:005): Internal system error
Line 10: END INTERFACE
The only solution I came up with is the following, but it's not really pretty IMHO, not to mention too much typing

Code:
#COMPILE EXE #DIM ALL 'I usually publish Interfaces that I use outside this file outside the class, like this: INTERFACE IncredibleInterface INHERIT CUSTOM METHOD AAA() METHOD BBB() METHOD CCC() END INTERFACE 'Here I create class CTest1 that has the "default implementation" of above's IncredibleInterface interface. CLASS CTest1 INTERFACE IncredibleInterface INHERIT CUSTOM METHOD AAA() ? "AAA1" END METHOD METHOD BBB() ? "BBB1" END METHOD METHOD CCC() ? "CCC1" END METHOD END INTERFACE END CLASS 'Nowe I want to create class CTest2, which implements the IncredibleInterface just like CTest1. 'I want to override 1 of the methods though, this is the only Method which its own implementation. CLASS CTest2 INSTANCE m_ct1 AS IncredibleInterface CLASS METHOD Create m_ct1 = CLASS "CTest1" END METHOD CLASS METHOD Destroy 'Yes, I know it's not neccessary, but I like to clean up my mess. m_ct1 = NOTHING END METHOD INTERFACE IncredibleInterface INHERIT CUSTOM METHOD AAA() m_ct1.AAA END METHOD METHOD BBB() ? "BBB2" END METHOD METHOD CCC() m_ct1.CCC END METHOD END INTERFACE END CLASS FUNCTION PBMAIN () AS LONG DIM CT1 AS IncredibleInterface DIM CT2 AS IncredibleInterface CT1 = CLASS "CTest1" CT1.AAA CT1.BBB CT1.CCC CT2 = CLASS "CTest2" CT2.AAA CT2.BBB CT2.CCC CT1 = NOTHING CT2 = NOTHING WAITKEY$ END FUNCTION
Best regards, Vincent
Comment