Let i have Three Class
1. ConfigurationA ---> SupperConf
2. ConfigurationB ---> SupperConf
3. CongigurationC ---> SupperConf
public interface SupperConf{}//empty
1. ConfigurationA{
public void setProA(String proA){}
}
2. ConfigurationB{
public void setProB(String proB){}
}
3. ConfigurationC{
public void setProC(String proB){}
}
public final class ConfigurationManager{
public static SupperConf getConfiguration(String confType){
SupperConf conf = null;
switch (confType)) {
case "confA":
configuration = new ConfigurationA();
break;
case "confB":
configuration = new ConfigurationB();
break;
case "confC":
configuration = new ConfigurationC();
break;
}
return configuration;
}
}
public class app{
public static void main(String agrs[]){
ConfigurationA confA = ConfigurationManager.getConfiguration("confA");
//Line 4 confA.setProA("proA");
}
}
What changes do i have to do so that my code compile at line 4 confA.setProA("proA");
I Know i can achieve using typecast like below
ConfigurationA confA = (ConfigurationA)ConfigurationManager.getConfiguration("confA");
I want to achieve doing some change in design or any design pattern in java so that i could achieve.
Aucun commentaire:
Enregistrer un commentaire