COM’s Versioning Story
COM’s
versioning solution for vtable-bound clients is that every interface
receives an IID and that interfaces are immutable once they are
published. Once you publish the interface, you must keep it the
same—no changes whatsoever. If you change an interface, then
according to the COM rules you must assign it a different IID. If you
assign a new IID to the interface, then you must decide what happens
when a client requests an old IID. You have a choice in this case.
You may decide that old clients must continue to run, in which case
you do not touch the old interface. You simply create a new interface
with the old methods plus your changes, and you implement both the
old interface and the new interface in the component. For example,
let’s say that the first version of the
IAccount interface is defined as follows:
'interface IAccount version 1 Public Sub MakeDeposit(ByVal Amount As Long) End Sub
Then the code for version 1 of the CChecking class
may be the following:
'class CChecking
Implements IAccount
Private m_Balance As Long
Private Sub IAccount_MakeDeposit(ByVal Amount As Long)
m_Balance = m_Balance + Amount
End SubLet’s say that later you must change
Amount to be a Double instead of a Long.
Then you would define a new interface:
'Interface IAccount2 (IAccount version 2) Public Sub MakeDeposit(ByVal Amount As Double) End Sub
Now that there is a new interface, the new version of CChecking would support both interfaces, as follows:
'class CChecking version 2 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access