Reputation: 63
I recently came on a quote in Essential com book by Don box
interface ICatDog : ICat, IDog { // illegal, multiple bases
COM prohibits multiple interface inheritance for a variety of reasons. One reason is that the binary representation of the resultant C++ abstract base class would not be compiler invariant
I was wondering if anyone knows why multiple bases is bad for com and would break compiler invariance.
Thank you
Upvotes: 0
Views: 664
Reputation: 12540
Limitation of MIDL tool/COM interface rules.
https://learn.microsoft.com/en-us/windows/win32/com/interface-design-rules
See also:
https://www.codeproject.com/Questions/877467/inheritance-two-ATL-interface
Extending MIDL interfaces and COM object design
https://www.codeproject.com/Articles/1249/A-Multiple-Inheritance-based-COM-Framework
https://www.ooportal.com/basic-com/module2/implementing-com-objects.php
http://computer-programming-forum.com/77-vc-atl/becc8c161a391551.htm
C++ COM design. Composition vs multiple inheritance
https://www.guusbosman.nl/downloads/PaperOop.html
"COM adopted the structure of C++ virtual function tables as the binary representation of an interface. COM interfaces are presented to clients as pointers to virtual tables. This is partly an inheritance from the DLL-technology what Microsoft uses for desktop environments. These allowed multiple client programs to link object implementations at execution time (dynamically)."
COM does not support multiple object inheritance like most object systems. Instead, it relies on inheritance from multiple interfaces for a single object. Each object inherits from IUnknown. The IUnknown interface includes the QueryInterface() method which is used for navigating between the interfaces of an object. In addition the AddRef() and Release() methods are included here. These are used for reference counting and garbage collection. In this way, every server object controls its own lifetime. Each interface has a Globally Unique Identifier (GUID), which must be registered with the Registry. In addition each class also has its own unique class ID (CLSID).
The situation in COM+ is a bit different. According to [Kirtland 97], COM+ will support implementation inheritance, together with object-references (COM doesn’t know object-references, only interface references). However, it is possible to use it, not mandatory. The article says, "it makes versioning a nightmare (see Version control)". In principle, most COM objects will be referred to by interfaces, not with object references.
Upvotes: 1