I am used to doing dynamic Binding in PHP this way
function ($className)
{
$obj = new $className();
.
.
.
}
here $className is a String parameter and based on name of the class an object of that class is created. So when I need to add more functionality I just add another class and everything get sorted out automatically.
Now I want to do something similar in Java. Right now my code is
public EditPart createEditPart(EditPart context, Object model) {
AbstractGraphicalEditPart part = null;
if(model instanceof Entreprise) {
part = new EntreprisePart();
else if(model instanceof Employee)
part = new EmployeePart();
.
.
.
}
My aim is that if I add a new Class to the package, I shouldn’t have the need to modify my createEditPart function.
How is it done in Java.
One option is to create a factory that each of your classes can register themselves with and then can be called to create the appropriate object.