inheritance? interface?

Hi, I have used inheritance incorrectly... could you point out how do I fix it please? My code looks like this:

publicabstractclass FeatureSpace{

publicvoid methodA(){

}

}

publicclass FeatureSpaceImplA{

publicvoid methodB(){

}

}

publicclass FeatureSpaceImplB{

publicvoid methodC(){

}

}

publicabstractclass FeatureSpaceBuilder(){

//This method takes an article content(String), analyse the article and create its

//feature space; the feature are stored in the method argument "space".

//Instead of returning a new FeatureSpace by the method itself,

//I'd like to pass a FeatureSpace object to the method, and modify it by the method;

//the reason is this method will be used iteratively, but eventually build only *one* FeatureSpace.

// Consider given a corpus of 100 articles, this method will be called

//100 times, building Features for each article, but store features in a

// single FeatureSpace as for the whole corpus. So instead of creating

// and returning then merging a new FeatureSpace each time, I just

// pass the single FeatureSpace object to the method every iteration, and

//modifies it.

abstractvoid buildFeatureSpace(String article, FeatureSpace space);

}

publicclass FeatureSpaceBuilderImplA(){

publicvoid buildFeatureSpace(String article, FeatureSpaceImplA space){

......

}

}

publicclass FeatureSpaceBuilderImplB(){

publicvoid buildFeatureSpace(String article, FeatureSpaceImplB space){

......

}

}

As you see, I need to use inheritance on the method arguments, but the compiler complains

"public abstract void buildFeatureSpace(String article,FeatureSpace space)"

needs to be implemented in both sub-classes.

I have defined separate methods in each sub class as:

""public abstract void buildFeatureSpace(String article,FeatureSpaceImplB space)"

"public abstract void buildFeatureSpace(String article,FeatureSpaceImplA space)"

Where "FeatureSpaceImplA" and "FeatureSpaceImplB" extends "FeatureSpace". But this doesnt work. I need to use specifc "FeatureSpace" in above two methods because their behaviors are different.

I feel that I may have done this in totally wrong way.... can you give me some advice pleas, many thanks!

[4266 byte] By [zqzuka] at [2007-11-27 8:25:34]
# 1
Method signatures have parentheses at the end, classes/interfaces don't.
prometheuzza at 2007-7-12 20:14:37 > top of Java-index,Java Essentials,Java Programming...
# 2
Yes, sorry those were typos! Thanks
zqzuka at 2007-7-12 20:14:38 > top of Java-index,Java Essentials,Java Programming...
# 3

> Yes, sorry those were typos! Thanks

I see no extends keyword(s) anywhere: with the incorrect parentheses fixed, there's nothing wrong with the code you posted.

But I see what you mean.

If you declare this method:

abstract void buildFeatureSpace(String article, FeatureSpace space);

in an abstract class, than all classes that extend that class should implement that exact method: you cannot change the signature of it no matter how much FeatureSpaceX looks like FeatureSpace.

prometheuzza at 2007-7-12 20:14:38 > top of Java-index,Java Essentials,Java Programming...
# 4

Ah sorry but thanks for pointing out! Please ignore the code below

"public abstract class FeatureSpaceBuilder(){",

I cannot re-edit it, but they should go like this:

public abstract class FeatureSpaceBuilder{

//This method takes an article content(String), analyse the article and create its

//feature space; the feature are stored in the method argument "space".

//Instead of returning a new FeatureSpace by the method itself,

//I'd like to pass a FeatureSpace object to the method, and modify it by the method;

//the reason is this method will be used iteratively, but eventually build only *one* FeatureSpace.

// Consider given a corpus of 100 articles, this method will be called

//100 times, building Features for each article, but store features in a

// single FeatureSpace as for the whole corpus. So instead of creating

// and returning then merging a new FeatureSpace each time, I just

// pass the single FeatureSpace object to the method every iteration, and

//modifies it.

abstract void buildFeatureSpace(String article, FeatureSpace space);

}

public class FeatureSpaceBuilderImplA extends FeatureSpaceBuilder{

public void buildFeatureSpace(String article, FeatureSpaceImplA space){

......

}

}

public class FeatureSpaceBuilderImplB extends FeatureSpaceBuilder{

public void buildFeatureSpace(String article, FeatureSpaceImplB space){

......

}

}

zqzuka at 2007-7-12 20:14:38 > top of Java-index,Java Essentials,Java Programming...
# 5

public abstract class FeatureSpace{

public void methodA(){

}

}

public class FeatureSpaceImplA{

public void methodB(){

}

}

public class FeatureSpaceImplB{

public void methodC(){

}

}

If the FeatureSpaceImplB is supposed to be an implementation of FeatureSpace, the extends keyword needs to be used.

boneysekha at 2007-7-12 20:14:38 > top of Java-index,Java Essentials,Java Programming...
# 6

> ...

> If the FeatureSpaceImplB is supposed to be an

> implementation of FeatureSpace, the extends keyword

> needs to be used.

Even with the extends keyword, the overridden method should look like this:public void buildFeatureSpace(String article, FeatureSpace space)

and not like this:public void buildFeatureSpace(String article, FeatureSpaceImplA space){

prometheuzza at 2007-7-12 20:14:38 > top of Java-index,Java Essentials,Java Programming...
# 7
thanks! I have solved the problem in other ways.
zqzuka at 2007-7-12 20:14:38 > top of Java-index,Java Essentials,Java Programming...