Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
platform
active.directory
adsi
adsi.iis-admin
base
com_ole
complus_mts
component_svcs
database
directx
gdi
graphics_mm
internet.client
internet.server
internet.server.isapi-dev
localization
mapi
messaging
msi
mslayerforunicode
multimedia
networking
networking.ipv6
sdk_install
security
shell
telephony.tapi_2
telephony.tapi_3
telephony.tsp
telephony.wte
tools
ui
ui_shell
win_base_svcs
win16
  
 
date: Fri, 14 Apr 2006 11:03:36 -0400,    group: microsoft.public.platformsdk.com_ole        back       


Extending COM interfaces with new functionality   
I have a few questions about what is appropriate when adding new features to 
your COM interface.

First- I have a Property that is an enumeration- it has both get and set 
methods. I'd like to add new values to this enumeration (new functionality 
is available now). Can I just add the values to the enumeration, or do I 
need to make a MyProperty2 that uses MyEnumeration2 (where MyEnumeration2 
has all of the old values plus the new ones). If I do this, how do I deal 
with users trying to read MyProperty when they've previously 'overridden' it 
with MyProperty2?

What about new methods? I assume I can't just add new methods to an existing 
interface... that would cause some kind of trouble with already compiled 
applications? So, if I have new methods to add, I'd have to have 
IMyInterface2 that has these methods. In my IDL, I'm having IMyInterface2 
derive from IMyInterface, allowing people to easily mix new functionality 
with old, particularly in languages like C# (no need to cast every time you 
need new functions- just always use the '2' version). Is this the way to go?
date: Fri, 14 Apr 2006 11:03:36 -0400   author:   Paul

Re: Extending COM interfaces with new functionality   
Paul  wrote:
> First- I have a Property that is an enumeration- it has both get and
> set methods. I'd like to add new values to this enumeration (new
> functionality is available now). Can I just add the values to the
> enumeration, or do I need to make a MyProperty2 that uses
> MyEnumeration2 (where MyEnumeration2 has all of the old values plus
> the new ones).

COM rules don't prohibit adding new enumeration values. But consider old 
clients that may suddenly start receiving values they don't expect and 
don't check for. If you are sure this is not a problem then go right 
ahead.

For example, you are safe if it's a simple property that just returns 
back whatever it was set to. In this case the old client won't see any 
new values since it never stores them in the first place.

> If I do this, how do I deal with users trying to read
> MyProperty when they've previously 'overridden' it with MyProperty2?

You choose a value from old enumeration that most closely reflects the 
semantics of the new enumeration (as in, breaks or unpleasantly 
surprises least number of old clients).

> What about new methods? I assume I can't just add new methods to an
> existing interface...

Absolutely not. Once published, a COM interface is immutable.

> that would cause some kind of trouble with
> already compiled applications? So, if I have new methods to add, I'd
> have to have IMyInterface2 that has these methods. In my IDL, I'm
> having IMyInterface2 derive from IMyInterface, allowing people to
> easily mix new functionality with old, particularly in languages like
> C# (no need to cast every time you need new functions- just always
> use the '2' version). Is this the way to go?

This is a very reasonable approach, yes.
-- 
With best wishes,
    Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not 
necessarily a good idea. It is hard to be sure where they are going to 
land, and it could be dangerous sitting under them as they fly 
overhead. -- RFC 1925
date: Fri, 14 Apr 2006 12:32:03 -0400   author:   Igor Tandetnik

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us