signals and slots vs. virtual_hook (was [PATCH] KFileDialog overwrite confirmation)

Ingo Klöcker kloecker at kde.org
Tue Jul 15 23:23:03 BST 2008


On Tuesday 15 July 2008, Rafael Fernández López wrote:
> Hi,
>
> > 1) There's BaseClass, where virtual_hook is defined initially
> > 2) There's MiddleClass: public BaseClass
> > 3) There's DerivedClass: public MiddleClass
> > 4) We decide that MiddleClass needs a new public, virtual function.
> > We implement that by way of a non-virtual public and by overriding
> > the virtual hook in MiddleClass and in DerivedClass.
> > 5) Where did the enum get defined?
> >   5.a) BaseClass, which means you must modify the most basic class
> > in the hierarchy, which sometimes you can't or don't want to
> >   5.b) MiddleClass, which is the "proper place"
>
> Yes, I'd say 5.b)
>
> > However, if you do modify MiddleClass, what happens when BaseClass
> > needs a virtual? It has to be sure not to use the same enum value
> > that was used in MiddleClass -- wherever that middle class ended up
> > being.
>
> That shouldn't be much trouble.
>
> enum NewVirtualMethods {
>      MyNewVirtual1 = 0,
>      MyNewVirtual2,
>      MyNewVirtual3,
>      VirtualMethodCount
> };
>
> so...
>
> enum NewVirtualMiddleClassMethods {
>      MyNewVirtual4 = VirtualMethodCount
> };

I don't get what you mean by this. Is NewVirtualMethods defined in 
BaseClass and NewVirtualMiddleClassMethods in MiddleClass? If yes, then 
the problem is that you cannot add another enum value to 
NewVirtualMethods because this would make a recompilation of 
MiddleClass necessary so that the new value for VirtualMethodCount is 
taken into account. Of course, one might use 

enum NewVirtualMiddleClassMethods {
     MyNewVirtual4 = VirtualMethodCount + 1000
};

instead in order to allow up to 1000 additional virtual methods to be 
added to BaseClass. This reminds me of line numbers in BASIC where you 
only used 10, 20, etc. as line numbers for your first version hoping 
that you'd never have to add more than 9 additional lines between lines 
10 and 20. ;-)


Regards,
Ingo
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 194 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20080716/7b04a84f/attachment.sig>


More information about the kde-core-devel mailing list