这种方法,我以前的时候确实没有用过,原因吗--入道不久,水不够深啊。
不过今天看来这种方法对于实现“对接口编程”确实很好,若在对一大堆相似的东西进行做相关的开发,如书中所说对数据库所引用的类型。这时用此就非常的不错,不仅实现了对接口的操作,而且也使代码的可读性非常好。
class AttributeDescriptors
{
public:
static AttributeDescriptors *forInteger(...)
{
return new IntegerDescriptor();
}
static AttributeDescriptors *forDate(...)
{
return new DateDescriptor();
}
static AttributeDescriptors *forString(...)
{
return new StringDescriptor();
}
}