我有一个分析字符串的类,如果字符串不为空或空字符串,它会根据子类的类型使用该对象创建一个新的字符串或新的日期。如果字符串为 null 或空,则返回空字符串。目前我称这个类转换器为类转换器,但我觉得这个名称具有误导性,是否有一个更好的名称任何人都可以想到这个类正在做什么?我想要一些直观的东西来使我的代码更具可读性。谢谢。
public abstract class Converter {
Object returnObject;
public Converter() {
}
public Object convert(String value)
{
if(!this.isEmpty(value))
{
this.setReturnObject(value);
}else
{
this.returnObject = "";
}
return this.getReturnObject();
}
protected boolean isEmpty(String value)
{
return (value != null && value.equalsIgnoreCase(""));
}
protected abstract void setReturnObject(String value);
protected Object getReturnObject(){
return this.returnObject;
}
}
public class NumberConverter extends Converter {
public NumberConverter() {
}
protected void setReturnObject(String value) {
this.returnObject = new Number(Integer.parseInt(value));
}
}
最佳答案
您可以使用 EntityMapper 或 EntityTransformer。
关于java - 需要帮助命名类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6994347/