Today I got my book ‘Head First Design Patterns’ in the mail. Pretty interesting stuff so far, however I do have a question about it’s contents.
I have no Java/C# background nor do I wish to jump into those languages right now (I’m trying to focus on C++ first). In the book is said that java does not have an implementation for interfaces… This would mean that for every change to that interface, you would have to modify all subclasses that implement the interface.
How is this done in C++? What am I missing?
What the author of the book meant, if you change the signatures of the members of the interface or add new ones, you will need to make those changes in the implementing classes as well so that they keep implementing the interface.
You can change the implementing classes whatever way you want as long you have the members of the interface implemented with exactly the same signatures (that is, with the same name, return type, and the order and type of parameters).
I have the impression that you don’t quite understand how interfaces work, so I suggest reading up the C# interface specification on MSDN which is quite clear on the subject I think (and it’s pretty much the same in Java except that in Java you use the ‘implements‘ keyword instead of a colon (:) to declare that a class implements a specific interface).