TypeEnum
MATERIAL,
OPERATION,
SIGNATURE;
class AbstractModule
TypeEnum typeEnum
String name
String color
class MaterialModule extends AbstractModule
some properties unique to this module
class OperationModule extends AbstractModule
some properties unique to this module
class SignatureModule extends AbstractModule
someProperties unique to this module
at some point a lot of xxxModule are made and stored in a AbstractModule list. Then later all that list is being iterated and a switch case is use to cast back the abstract module to its child class and do stuff
switch (module.getTypeEnum) {
case MATERIAL:
MaterialModule materialModule = (MaterialModule) module;
//do stuff with materialModule unique property
break;
case OPERATION:
OperationModule operationModule = (OperationModule) module;
//do stuff with operationModule unique property
break;
case SIGNATURE:
SignatureModule signatureModule = (SignatureModule) module;
//do stuff with signature module unique property
break;
each "do stuff with module unique property" should be in a method in each child class
that way you can just call module.doModuleStuff() instead of doing a switch, well no because I still need to cast it back to its child class for that.
Problem is, is If put this code in each child class, how do I call the right method when my list contains AbstractModules? And I mean without having this typeEnum and switch case.
Thanks.