我有一个abstract class
装载机:
public abstract class Loader
{
private String EXTENSION = ".xxx";
private String dir;
public abstract Object load(String file);
public abstract List<?> loadList(String file, int number);
public Loader(String dir)
{
this.dir = dir.replace("\\", "/") + "/";;
}
public String formatName(String name)
{
return dir + name + EXTENSION;
}
}
它的子类应该能够改变 EXTENSION
public class MidiLoader extends Loader
{
private String EXTENSION = ".mid";
public MidiLoader(String dir)
{
super(dir);
}
public MidiLoader()
{
super(Constants.SOUNDDIR);
}
@Override
public Sequence load(String file)
{
blah
}
public List<Sequence> loadList(String file, int number)
{
blah
}
}
EXTENSION ".mid" 应该由Loader
'sformatName
函数使用。我如何让它做到这一点(不重复代码)?
谢谢。