Interfaces in C++
Following a discussion on a mailing list tonight about object-oriented v procedural programming, I’ve been doing a little digging.
The discussion was on whether objects should have their own print method or should be passed to an external Printer object that handles that function.
One solution in Java would be for them to implement an Interface Printable that provided a toString() method. That way, the object remains decoupled from the output process but encapsulation is preserved and the Printer object (which takes a Printable object) does not need to know anything about the internals of the objects it is passed.
Which led to the question, can you do this in C++?
It looks as if Interfaces do not yet exist in C++ in spite of some interest. There is a library under development however for submission to Boost.
March 28th, 2006 at 11:59 pm
More digging. There’s a good article in Dr Dobb’s Journal about this for anyone interested:
Keeping interfaces and implementations separate (Registration required)