Identifying a class which is extending an abstract class
Good Evening,
I'm doing a major refactoring of http://wiki2xhtml.sourceforge.net/ to finally get better overview and maintainability. (I started the project when I decided to start programming, so – you get it, right? ;))
At the moment I wonder how to solve the problem I'll describe now:
Every file will be put through several parsers (like one for links, one for tables, one for images, etc.):
public class WikiLinks extends WikiTask { ... }
public class WikiTables extends WikiTask { ... }
The files will then be parsed about this way:
public class WikiFile {
...
public void parse() {
//Run all parsers on this file.
if (!parse) return;
WikiTask task = new WikiLinks();
do {
task.parse(this);
} while ((task = task.nextTask()) != null);
}
}
S开发者_运维知识库ometimes I may want to use no parser at all (for files that only need to be copied), or only a chosen one (e.g. for testing purposes). So before running task.parse() I need to check whether this certain parser is actually necessary/desired. (Perhaps via Blacklist or Whitelist.)
What would you suggest for comparing? An ID for each WikiTask (how to do?)? Comparing the task Object itself against a new instance of a WikiTask (overhead)?
i'm sorry but I don't really get the idea of your parse function. If you don't want to use a parser, set parse to false? :)
If I try to guess what you want...I would simply use an enum. Your tasks could hold a ParserType type;
, so you could do sth. like if(task.getParserType() == this.getParserType() ) { task.parse(this) }
You surely need to use a List if you want different parsers for a certain task. Regards.
精彩评论