Z
zsomi
Hi all!
I'm newby in java.
I've the following problem:
I need to write some classes with the abstract Factory pattern.
I have written it in c++, but I cant in java. I tried this (It's very
simple):
//A.java
package up;
public abstract class A {
public abstract String function(String s);
}
//AF.java
package up;
public class AF {
private static A a;
public static void main(String[] args) {
AF af = new AF();
A a2 = AF.getConcrete("C");
String vmi = a2.function("ird ki");
System.out.println(vmi);
}
public A getConcrete(String s) {
if (s.compareTo("C") == 0 ) {
a = new C();
}
return a;
}
}
//C.java
package up;
public class C extends A {
public String function(String s) {
System.out.println(s);
return s;
}
}
So the problems:
If I dont put them into the package, it works fine. If I put, then I
can compile it, but a cant run. I tried various ways, for example:
java AF, java -cp . AF , java up.AF, java -cp . up.AF
I tried to use .jar : jar cf uppkg.jar *.class
java -cp .:./uppkg.jar AF , java -cp .:./uppkg.jar up.AF
I got : java.lang.NoClassDefFoundError: up/AF (for every try)
WHY??? What did I wrong?
And my biggest problem is: I should use abstract factory with(becouse
of) different java toolkits.
So it would be better, if I can put the classes of different toolkit
into different packages and the abstract classes (with the factory
class) into another package.
For example: ~/lib/Factory: A.class, AF.class -->package interfaces;
~/lib/Factory/Dcm4che: B.class, C.class --
package othertk;
AND: my main should be in test.java in ~/apps/test
But I see, that it's not possible of the cross references. Am I right?
What can be a pretty solution of this problem?
Can anybody help me? Thanks a lot: Zsomi
I'm newby in java.
I've the following problem:
I need to write some classes with the abstract Factory pattern.
I have written it in c++, but I cant in java. I tried this (It's very
simple):
//A.java
package up;
public abstract class A {
public abstract String function(String s);
}
//AF.java
package up;
public class AF {
private static A a;
public static void main(String[] args) {
AF af = new AF();
A a2 = AF.getConcrete("C");
String vmi = a2.function("ird ki");
System.out.println(vmi);
}
public A getConcrete(String s) {
if (s.compareTo("C") == 0 ) {
a = new C();
}
return a;
}
}
//C.java
package up;
public class C extends A {
public String function(String s) {
System.out.println(s);
return s;
}
}
So the problems:
If I dont put them into the package, it works fine. If I put, then I
can compile it, but a cant run. I tried various ways, for example:
java AF, java -cp . AF , java up.AF, java -cp . up.AF
I tried to use .jar : jar cf uppkg.jar *.class
java -cp .:./uppkg.jar AF , java -cp .:./uppkg.jar up.AF
I got : java.lang.NoClassDefFoundError: up/AF (for every try)
WHY??? What did I wrong?
And my biggest problem is: I should use abstract factory with(becouse
of) different java toolkits.
So it would be better, if I can put the classes of different toolkit
into different packages and the abstract classes (with the factory
class) into another package.
For example: ~/lib/Factory: A.class, AF.class -->package interfaces;
~/lib/Factory/Dcm4che: B.class, C.class --
~/lib/Factory/Othertk: D.class, E.class -->package dcm4che;
package othertk;
AND: my main should be in test.java in ~/apps/test
But I see, that it's not possible of the cross references. Am I right?
What can be a pretty solution of this problem?
Can anybody help me? Thanks a lot: Zsomi