T
Tim Clacy
Can this be done... or is there a better way to achieve the same objective?
If an interface class contains only references (to yet more interface
classes), then can those references be initialised in a concrete derived
class? To have to initialise them in the interface class constructor makes
the interface a concrete class. I suppose they could be pointers instead of
references... but why necessary; surely the compiler has all the information
that it needs to do the job?
The objective is to be able to provide a class interface to concrete
instance(s) without exposing any implementation detail or data (private or
otherwise); in fact, the only concrete function should be the factory
interface. Here's the general idea [see below] where
'Implementation::Connect' is a function that returns a reference to a
functor derived from 'Port':
struct Port
{
void virtual operator()() = 0;
};
struct Interface
{
Port& I1;
Port& I2;
:
};
struct Implementation : Interface
{
Implementation() :
I1 (Connect(fn1)),
I2 (Connect(fn2)))
{ }
void fn1();
void fn2();
:
};
Eager to see what the gurus say...
Tim
If an interface class contains only references (to yet more interface
classes), then can those references be initialised in a concrete derived
class? To have to initialise them in the interface class constructor makes
the interface a concrete class. I suppose they could be pointers instead of
references... but why necessary; surely the compiler has all the information
that it needs to do the job?
The objective is to be able to provide a class interface to concrete
instance(s) without exposing any implementation detail or data (private or
otherwise); in fact, the only concrete function should be the factory
interface. Here's the general idea [see below] where
'Implementation::Connect' is a function that returns a reference to a
functor derived from 'Port':
struct Port
{
void virtual operator()() = 0;
};
struct Interface
{
Port& I1;
Port& I2;
:
};
struct Implementation : Interface
{
Implementation() :
I1 (Connect(fn1)),
I2 (Connect(fn2)))
{ }
void fn1();
void fn2();
:
};
Eager to see what the gurus say...
Tim