Re: How to separate interface from implementation when using JARs?



Marc <MJT.Keijsers@xxxxxxxxx> writes:
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.

If I understand your issue correctly, you can achieve something
similar by creating separate jar files for interfaces and
implementations. With that approach, you could release only the
implementation jar when fixing a bug.

If you have a distributed system, you could dynamically download
updates by distributing jars only to class servers. One Java
technology that supports this is Jini (http://www.jini.org).

Regards,

Patrick

------------------------------------------------------------------------
S P Engineering, Inc. | Large scale, mission-critical, distributed OO
| systems design and implementation.
pjm@xxxxxxx | (C++, Java, Common Lisp, Jini, middleware, SOA)
.



Relevant Pages

  • Re: How to separate interface from implementation when using JARs?
    ... In Java I can use the interface concept. ... int MyAdd; ... client JAR which I should also redistibute. ...
    (comp.lang.java.programmer)
  • Re: How to separate interface from implementation when using JARs?
    ... In Java I can use the interface concept. ... int MyAdd; ... I would use this class as an import in my client code: ... recompile my client code will recompile leading to a new ...
    (comp.lang.java.programmer)
  • Re: Regarding Interface..
    ... private static final int a=10; ... interface A { ... Actually multiple inheritance can be achieved in Java ...
    (comp.lang.java.programmer)
  • regarding a doubt in interfaces
    ... int main{ ... but in java, ... public static void main{ ... 4)is it possible to write a interface in a class? ...
    (comp.lang.java.help)
  • Re: Darkroom software Help
    ... Apple's computer operating system OS-X includes the Java ... programing language, compiler, and integration software. ... have an Apple this fall. ... Said that, my system is based on a commercial lab interface, the ...
    (rec.photo.darkroom)