[Qt-interest] Non-Virtual Interface Idiom

Thiago Macieira thiago at kde.org
Mon Dec 20 12:01:24 CET 2010


On Monday, 20 de December de 2010 10:34:10 Oliver.Knoll at comit.ch wrote:
> I think Herb Sutter did not understand the point of interfaces: he mixes
> implementation with interfaces. When I talk about "interfaces" I think
> "Java interfaces", and in C++ that renders to pure virtual classes (in my
> understanding of "interfaces").
[snip]
> But for interfaces this totally does not make sense to me, and the fact that
> this practise has had no impact since 2001 (the time this article was
> published) tells me that others agree ;)

Considering who Herb Sutter is, I wouldn't say he "did not understand the 
point of interfaces". There's no keyword "interface" in C++ and Java concepts 
have absolutely no relevance to us and him.

An interface is just the contract between the class and its users. It's the 
API, both the public one and the protected and private one. In that sense, he 
has made no confusion and your argument that they have to be public pure 
virtual doesn't apply.

However, in the end, I don't agree with his argument. There are many 
legitimate cases for having public virtual methods. There are also many cases 
where his recommendation makes sense, see:

	http://doc.trolltech.com/3.3/qiodevice.html#writeBlock
vs
	http://doc.qt.nokia.com/latest/qiodevice.html#write
	http://doc.qt.nokia.com/latest/qiodevice.html#writeData

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Senior Product Manager - Nokia, Qt Development Frameworks
      PGP/GPG: 0x6EF45358; fingerprint:
      E067 918B B660 DBD1 105C  966C 33F5 F005 6EF4 5358
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
Url : http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20101220/07624908/attachment.bin 


More information about the Qt-interest-old mailing list