Does VisiBroker for C++ allow implementation inheritance ?

From Support
Jump to: navigation, search

Question:

When an interface inherits from another interface the idl2cpp IDL compiler seems to force the most derived interface to implement all of the operations defined for the interface hierarchy. Does VisiBroker for C++ allow implementation inheritance ?

Version: 3.x (all)

Answer:

Inheritance in IDL is a composition technique and does not imply inheritance of the implementation (since an implementation language may not even support inheritance). The composed interface specifies the operations and attributes that the implementation must (somehow) support, but CORBA does not mandate how. The idl2cpp IDL compiler forces the most derived interface implement all of the operations defined for the interface. This approach is CORBA compliant, but can be inconvenient for developers working in languages that would support a natural implementation of such a composed interface through inheritance.

Assume the following IDL:

interface A { void doA();

};

interface B {

void doB();

};

interface C : A, B {

void doC();

};

interface D : A {

void doD();

};

The default code generated by the idl2cpp compiler will require the implementation class for interface C to inherit only from _sk_C and implement methods doA(), doB(), doC(), and doD(). There is no implementation inheritance. This means that the implementation class for interface D must also implement method doA() (as well as doD()).

An alternate approach is to use the idl2cpp -virtual_impl_inh option which relaxes the restriction that derived operations are prototyped as pure virtual functions in the derived class definition. If the idl is compiled using the option, then the implementation class for interface C inherits from _sk_C, AImpl, and BImpl, and only needs to implement method doC() since it will inherit the implementations for methods doA() and doB(). For example:

class AImpl: public _sk_A {

public:

AImpl(const char *object_name=NULL);

void doA();

};

class BImpl: public _sk_B {

public:

BImpl(const char *object_name=NULL);

void doB();

};

class CImpl: public _sk_C, public AImpl, public BImpl {

public:

CImpl(const char *object_name=NULL);

void doC();

};

Yet another approach is to use the TIE mechanism. The most derived object is created and then associated with the appropriate tie class. So the tie class for object passes requests to the real object which takes advantage of the inherited method implementation. The tie class ensures that only legal operations will be allowed through to the real object.

Article originally contributed by