Proposing the removal of virtual_hooks (or how you can add a virtual method without using "virtual")

R.F. Pels ruurd at tiscali.nl
Mon Mar 6 00:13:54 GMT 2006


On Sunday 5 March 2006 23.18, Frans Englich wrote:

>>> Another way to preserve BC is to use the visitor/double dispatch
>>> pattern. It can be argued to be a bit heavy code-wise, but achieves the
>>> goal and can also be fast, depending on various factors. Major
>>> pros/cons:

>> Would you mind elaborate on what that is?
>
> Ok, attached is a visitor pattern discussion. I'm told it is in GOF's
> Pattern Design book, 

It is.

> you can read about it in wikipedia, google for it, etc. I might very well be
> "wrong" on this, show an incomplete picture, and  so forth. I have never
> seen anyone use it for the purpose of preserving BC, but by my common
> sense(TM) it should be possible to use it that way. 

Well, double dispatch is a bit of overkill to use if there is only a single 
type of inner object. Besides, it's possible to extend the inner class 
without modifying the outer class provided you have a way to derive from the 
inner class and provided you have a way in the interface of the containing 
class to set the pointer, i.e.:

	Outer::Outer(Inner* p): inner(p) {}

Or you can use a factory to create the inner class based on the constructor 
arguments...

> I use the visitor pattern in kdenonbeta/kdom/xpath, but that's mainly for
> other reasons(not for preserving BC).

Ofcourse you do. Because you have to deal with objects derived from a common 
class but do not know in advance which exact type they are. Visitor pattern 
is an example of the rule that 'Any software engineering problem can be 
solved by adding an extra level of indirection'. Pimpl is another example, as 
is En-Masse Delegation, BTW.

-- 
R.F. Pels,  3e Rompert 118,  5233 AL  's-Hertogenbosch,  The Netherlands
+31736414590        ruurd at tiscali.nl       http://home.tiscali.nl/~ruurd





More information about the kde-core-devel mailing list