4

Why doesn't IHTMLDocument3, for example, inherit IHTMLDocument2? Why doesn't IAnyMicrosoftInterface(N) inherit IAnyMicrosoftInterface(N-1)?

New interfaces just contain only new functions, but they don't inherit previous interface's functions. Can I be sure that if some object supports ISomeInterface5 then it also supports ISomeInterface4? I'm writing some wrappers for COM code and I need to decide, for example, shall html_document3 be derived from html_document2.

Steve Mitcham
  • 5,268
  • 1
  • 28
  • 56

1 Answers1

2

Why doesn't IAnyMicrosoftInterface(N) inherit IAnyMicrosoftInterface(N-1)?

Here you go examples of the opposite:

The IFilterGraph3 interface inherits from IFilterGraph2. IFilterGraph3 also has these types of members:

Or

The ID2D1Bitmap1 interface inherits from ID2D1Bitmap. ID2D1Bitmap1 also has these types of members:

Those are two approaches in design of COM interfaces. It can work out both ways. Both ways all new and old methods are accessible through both interfaces (and possibly through new interface only). If you choose to inherit, you basically duplicate all old methods on new interface and one does not need old interface at all. If you choose to not inherit you get the option of redefining certain methods to, for instance, add new parameters and have still everything look well all together.

Can I be sure that if some object supports ISomeInterface5 then it also supports ISomeInterface4?

No. It might be exactly the point that newer implementation does not drag too much of legacy stuff in. Or, designer prefers to reuse older/newer code on the same class in the way that old and new implementation is backed by the same class. Regular COM rules apply here: an object might implement many interfaces; you QueryInterface to discover them programmatically, and you make assumptions on interface availability using documentation in case it is clearly promised that specific implementation offers multiple interfaces, esp. such as also older version of evolving interface.

Roman R.
  • 68,205
  • 6
  • 94
  • 158
  • I don't understand. What's the point having IHTMLDocument3 if I'm not sure there is IHTMLDocument2? IHTMLDocument3 can't be used without IHTMLDocument2 because the last one contains base functionality. For example, how can I use ITextFile if there is no guarantee that the base IFile is supported? – reinterpret_alexey Feb 04 '15 at 11:13
  • Are you asking in general or specifically about `IHTMLDocumentN`? In general, `IFooX` might or might not be needed once you have `IFooY`. IHTMLDocument3 however only adds new methods, so it is assumed that older stuff is also there. It just does not have to always be this way. – Roman R. Feb 04 '15 at 11:25
  • I just wanted to know how to handle such interfaces. E.g., interfaces which doesn't inherit previous versions. MSDN just sucks. It should be written explicitly on the top of documentation page: "If an object supports IHTMLDocumentN, it supports all the previous versions". Why to exclude previous functionality from a new interface without such warnings? – reinterpret_alexey Feb 04 '15 at 11:37
  • It should not be written this way. Or otherwise it would be a strong constraint for developers, which once published they would have to comply with. with respect to IHTMLDocument3, you simply assume IHTMLDocument2 is also there. This does not have to be a general rule. – Roman R. Feb 04 '15 at 11:42