Page #55 (Implementing COM Objects)

< BACK  NEXT >
[oR]

Tear-Off Interfaces

An object may support a large number of interfaces. In some scenarios, some of the interfaces are used rarely (for example, for backward compatibility) or transiently.

In order to reduce the overhead of such rarely used interfaces, a developer may not choose to support them in the object implementation. Instead, when the request for such an interface is made (via QueryInterface, for example), the vtbl for the interface is dynamically constructed and returned. The last Release on the interface will destroy this vtbl.

Such a technique is referred to as a tear-off, as a new interface is torn off on demand, that is, constructed and destroyed on the fly.

Note that this technique potentially returns different physical results for identical QueryInterface requests. However, this does not break the component model as long as the tear-off interface honors all the rules of IUnknown, such as object-identity, symmetry, etc.

Academically, a tear-off is a clever technique that manipulates the loophole in COM s specifications. However, as we will see in a later chapter, this technique breaks down if the interface has to be marshaled, for example, across a process boundary.

Implementing a tear-off interface is left as an exercise for the reader.

At this point, we completely understand the rules of COM object implementation. Let s explore the possibility of reusing third-party components and its impact on the design.


< BACK  NEXT >


COM+ Programming. A Practical Guide Using Visual C++ and ATL
COM+ Programming. A Practical Guide Using Visual C++ and ATL
ISBN: 130886742
EAN: N/A
Year: 2000
Pages: 129

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net