Java: No interface implementation?

Java: No interface implementation?

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?

Free library like Java's Robot class for C++


Benefits of Parallel programming [closed]
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..
Profiler for a C++ module in a C# app
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)..
What exactly happens when my process is killed?
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)..
Best way to pass char* to .Net

Natural Language Processing in C++ [closed]

Marshalling data for C#


DllImport a c++ DLL in to a C# app, BYTE * p

if you want to change the signature of a method in an interface, a good IDE (eclipse, netbeans...) can help you with refactoring all the classes implementing this interface..


The C++ equivalent of a Java interface would be a class with only pure virtual methods.. You mentioned that you've "seen plenty of these Runnable/Threadable interfaces that can be modified without touching those subclasses." It's hard to say for sure from your description, but what you might have seen before is something like this:.
Runnable r = new Runnable() {     public void run() {         // do something here     } }; 
This is an anonymous class implementing the Runnable interface; it is not modifying the interface in any way..


It's the same situation in C++.

. C++ doesn't have an interface keyword, but a pure virtual class, with all pure virtual methods, is the same idea.. If you changed method signatures in the pure virtual class, all its subclasses must follow suit in order to compile..


An interface defines a contract that the class implementing the interface is expected to follow.

This is akin to an abstract base class - which basically delegates the implementation of the methods to the deriving class.. Yes, if you modify the interface - you would have to modify all the classes that implement that interface.

My guess is that the instances of Runnable that you would have seen in Java code are anonymous classes which actually implement Runnable rather than modify the interface itself..
Runnable myOwnThread = new Runnable() {   public void run() {    // Do something here   } }; 
In Java, you are not allowed to modify the interfaces (and classes) provided in the standard library.

The equivalent in C++ could be the pure virtual class..


Ok I'll askt he obvious question:. If you want to do design patterns in C++ why would you read anything other than the original Gang of Four Design Patterns book?. And yes a C++ class with pure virtual methods is the equivalent to a Java or C# interface..

85 out of 100 based on 45 user ratings 1195 reviews