Knowing that Storage is an interface and StorageXX are its implementations, I want to know if it is possible to replace the following code...
Storage storage;
switch (storageType) {
case "list":
storage = new StorageList();
break;
case "map":
storage = new StorageMap();
break;
case "db":
storage = new StorageDB();
break;
default:
throw new UnsupportedStorageTypeException();
}
... by a "dynamic constructor" of Storage that taken a String parameter (the storageType) , returns the instance I want in each case...
It doesn't matter if Storage should be an abstract class.
I would rather prefer to avoid any switch statement if possible.