[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

4.3.1.4 Interface and implementation inheritance

From time to time there might be a need or want for using normal inheritance together with SCF. In practice there are two times you want to do this; interface deriving from another interface to add methods and deriving from an implementation class to add new interfaces.

In the first case where you want an interface to extend another, the declaration of the interfaces is straight forward using normal C++ inheritance. However, to make the implementation class aware of the base interfaces it should also expose you need to use the scfFakeInterface<> template class in the parameter to scfImplementationN<>.

Example:

 
// Abstract interface file (itest2.h)
struct iTestBase : public virtual iBase
{
  SCF_INTERFACE (iTestBase, 1, 0, 0);
  ...
  virtual void SomeFunction () = 0;
};

struct iTest2 : public iTestBase
{
  SCF_INTERFACE (iTest2, 1, 0, 0);
  ...
  virtual void NewFunction () = 0;
};

// Concrete implementation header (test2.h)
class Test2 : public scfImplementation2<Test2, 
                                        scfFakeInterface<iTestBase>,
                                        iTest2>
{
  ...
};

The other situation is when you want to take an already existing implementation class, derive from it and add one or more new interfaces. Using only normal C++ inheritance and scfImplementationN<> like above is the right way to go if the base class does not implement any SCF interfaces, if they do you need to use the extra functionality that the template scfImplementationExtN<>.

scfImplementationExtN<> have same template parameters as scfImplementationN<> with one difference, the second parameter is the base class to use.

Example: Lets extend Test2 from above with one more interface

 
struct iNewIf : public virtual iBase
{
  SCF_INTERFACE (iNewIf, 1, 0, 0);
  virtual void PrintMe () = 0;
}

class NewTest2 : public scfImplementationExt1<NewTest2, Test2, iNewIf>
{
  ...
  void PrintMe ();
}


[ < ] [ > ]   [ << ] [ Up ] [ >> ]

This document was generated using texi2html 1.76.