|
|
|
date: Fri, 14 Apr 2006 11:03:36 -0400,
group: microsoft.public.platformsdk.com_ole
back
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
|
|