C++ “Interfaces”#
Bringing It All Together#
C++ has a toolset for
Inheritance
Dynamic dispatch
Does not make any policies
Java does
interface
,implements
: interfaces (C++: pure virtual) and their implementation
Programmer’s choice how to use tools
⟶ very easily incomprehensible code is created
⟶ best practices!
Interfaces#
Bringing it all together: an interface is defined like so …
Virtual destructor, with an empty implementation (remember, destructors cannot be abstract/pure virtual)
Only abstract/pure virtual methods
class Interface
{
public:
virtual ~Interface() {}
virtual void method() const = 0;
};
Ideally nothing else
Programmers are invited to break the rules!
⟶ Personal taste, combined with respect for colleagues