Interface Versions and Inheritance

Unlike C++ classes, COM interfaces do not use inheritance to express specializations of objects. Usually all interfaces are derived from FUnknown. This is because interfaces never must change after they have been released. The VST Module Architecture Interfaces use inheritance only for versioning! All specializations will be modelled as separate interface!

For example the C++ classes

class Shape
{
public:
        void setPosition (long x, long y);
protected:
        long x;
        long y;
};
class Rect : public Shape
{
public:
        void setDimension (long width, long height);
protected:
        long width;
        long height;
};

expressed in COM, define an interface for each inheritance level:

class IShape : public FUnknown
{
public:
        virtual void setPosition (long x, long y) = 0;
};
class IRect : public FUnknown
{
public:
        virtual void setDimension (long width, long height) = 0;
};

In the next program version there need to be changes to the Shape class that look like this:

class Shape
{
public:
        void setPosition (long x, long y);
        void setColor (Color color);
protected:
        long x;
        long y;
        Color color;
};

The COM representation now reflect the changes to Shape by adding a new interface that inherits from IShape and looks like the following code, while the former interface definitions remain the same:

class IShape2 : public IShape
{
public:
        virtual void setColor (Color color) = 0;
};
Empty

Copyright ©2008 Steinberg Media Technologies. All Rights Reserved.