I'm trying to use inheritance and polymorphism to make it easy for the program to be enhance to many more rules. ClassificationRule
is the base class and RuleFirstOccrnc
and RuleOccrncCount
and derived classes and by using the same non-static apply()
method ClassificationRule
should invoke all other non-static apply()
method. I'm just starting on Java and I'm not sure if I'm doing it right. Can anyone tell me if I'm using inheritance or just calling the apply()
method?
//PrioritRule Class
public class PrioritRuls {
final static ArrayList<ClassificationRule> rulesA
= new ArrayList<ClassificationRule>();
static{
rulesA.add( new RuleFirstOccrnc() );
rulesA.add( new RuleOccrncCount() );
}
public static void prioritize( final String aUserInput ){
for (ClassificationRule rule:rulesA)
rule.apply(aUserInput);
}
}
// ClassificationRule Class - Based Class
public class ClassificationRule {
public void apply (final String aUserInput) {
apply( aUserInput );
}
}
//RuleFirstOccrnc - Derived Class
public class RuleFirstOccrnc extends ClassificationRule {
public void apply ( final String aUserInput ) {
for( TweetCat t: TwtClassif.tCat )
applyFirstOccurrenceRuleTo( t, aUserInput );
}
* * *
//RuleOccrncCount - Derived Class
public class RuleOccrncCount extends ClassificationRule {
public void apply ( final String aUserInput ) {
for( TweetCat t: TwtClassif.tCat )
applyOccurrenceCountRuleTo( t, aUserInput );
}
* * *
aUserInput
)? It makes it harder to tell what you're doing, without giving you any benefit. – Clockwork-Muse Apr 30 '12 at 16:28