Re: How to separate interface from implementation when using JARs?
On Sep 17, 1:33 pm, MJT.Keijs...@gmail.com wrote a message and was too
soon to send :-), Full text below:
Hi,
In an engineering world where I used to be working with C++ I am now
shiftnig to Java. In C++ I would publishe my interfaces in header
files. In Java I can use the interface concept.
However this is not sufficient for me. I want to be able to full
separate the implementation from the interface of e.g. a class
method.
Example:
public interface MyMath {
int MyAdd(int a, int n);
}
class Calculate implements MyMath {
int MyAdd(int a, int n) {
return a - b;
}
I would use this class as an import in my client code:
#import Calculate
class client {
void DoIt() {
Calculate c = new Calculate();
int sum = c.MyAdd(9,7);
}
Once I discover the implementation error in the Calculate and want to
fix that I do not want to change the client code to require
recompilation/distribution. In C++ I would not have to change the
header file,only a cpp file. I would compile and link the math library
to a dll and redistribute only that DLL. In basic JAVA, when I
recompile my client code will recompile leading to a new (changed?)
client JAR which I should also redistibute. This is undesired for me.
I played with RMI and managed to do this when using two JVM's, but in
the 'simple' scenario where I want to divide a project in separate
JARs for maintainability, do I have to accept the fact that the client
code changes, or must I apply RMI?
Kind Regards,
Marc