Question About Type Safety
I was reading Robert C Martin's article here:
http://today.java.net/pub/a/today/2005/03/09/factory.html
and I had a question about this section:
<begin quote>
publicinterface DynamicListFactory{
List make(String listType);}
publicclass NormalDynamicListFactoryimplements DynamicListFactory{
public List make(String listType){
if (listType.equals("InsertionList"))
returnnew LinkedList();
elseif (listType.equals("IndexedAccessList"))
returnnew ArrayList();
else
returnnull;
}
}
Code like this ought to make your hackles rise. Code like this is not type safe! On the other hand, code like this eliminates unnecessary recompiles and redeployments for volatile factories. Which of these two is more important depends on the project, and is a matter of some debate.
<end quote>
Is this code not type safe because if you mistype the name it will return null and you'll get a runtime error?
Thanks,
John

