Mailinglist Archive: zypp-devel (66 mails)

< Previous Next >
[zypp-devel] Re: question about Media virtuals
  • From: Michael Andres <ma@xxxxxxx>
  • Date: Wed, 25 Feb 2009 11:45:44 +0100
  • Message-id: <200902251145.45433.ma@xxxxxxx>
On Tuesday 24 February 2009 18:49:21 you wrote:
question :-)

MediaHandler has virtuals, and provide default implementation.

All concrete handlers override them, foo, only to call
MediaHandler::foo() in the reimplementation. What is the purpose of this?

Depends on the design of the base class.

This is usually the case if the base class defines all pure virtual:

virtual int pure() = 0;

You usually do this to enforce each derived class to check and explicitly
state that the provided default implementation is suitable.

If you add a new pure virtual, or change it's signature, all classes must be
visited and checked.


(at least, makes really hard and boring to do any refactoring changing
method signatures).

That's the intent. If you add a method or change the signature the compiler
will tell you all locations you have to touch and review. That's esp.
helpfull if not all developers are that familiar with the code.


We e.g failed to do this in the callback classes, and sometimes pay the price.
It happens someone changes a callback signature, and no one recognizes it,
because the compiler does not complain (per default not even warns).

needs: -Woverloaded-virtual (-Wnon-virtual-dtor)

If the callback methods were pure, it would not have happened that e.g.
pkg-kit listens to the wrong callback for more than a year. That would have
saved investgation time time and several bugreports. Just for the convenience
of 'easy refactoring'.


Now as we have automated builds, thus recognize early if something does not
compile, I'd tend to introduce more pure virtuals instead of hoping all
others turn on the proper compiler warning and also read them.


Your experience may be 'hard and boring', but (no only) if you have to fix
things under preassure, you will appreciate the compiler assistance.


While refactoring the '= 0' hinders. Thats why you could do:

- Create some header e.g. 'base/virtuals.h'

#ifdef REFACTORING
#warning PURE VIRTUALS DIABLED WHILE REFACTORING
#define PUREVIRTUAL
#else
#define PUREVIRTUAL =0
#endif

- Include it an all header files that may use pure vitrtuals:

#include "zypp/base/virtuals.h"

...
virtual int pure() PUREVIRTUAL;

- And configure to compile with -DREFACTORING



--

cu,
Michael Andres

+------------------------------------------------------------------+
Key fingerprint = 2DFA 5D73 18B1 E7EF A862 27AC 3FB8 9E3A 27C6 B0E4
+------------------------------------------------------------------+
Michael Andres YaST Development ma@xxxxxxxxxx
SUSE LINUX Products GmbH, GF: Markus Rex, HRB 16746 (AG Nuernberg)
Maxfeldstrasse 5, D-90409 Nuernberg, Germany, ++49 (0)911 - 740 53-0
+------------------------------------------------------------------+

--
To unsubscribe, e-mail: zypp-devel+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: zypp-devel+help@xxxxxxxxxxxx

< Previous Next >
Follow Ups