Hi
I've been wondering about how "programming to an interface, not an
implementation" works in C++.
As I understand it, I start with an abstract base class as the interface:
class TestInterface {
public:
...
virtual int foo() = 0;
...
};
- and use this for the implementation:
class TestImp : public TestInterface {
public:
...
virtual int foo();
...
private:
...
};
In an client class I may then do something like:
Client::UseFoo(TestInterface *test) {
test->foo();
}
But that's just polymorphism - so "Interface = Polymorphism"?
And the test object still needs to be created somewhere, like:
Client::UseFoo() {
TestImp *test = new TestImp;
test->foo();
delete test;
}
So the client still needs to know about the implementation. So why use an
interface if polymorphism is not needed? What if the private part of TestImp
contained some classes from an external lib, that the client should not know
about?
Obviously I'm missing something :)