"dynamic" is the key
word above. With
class.forName(
string ).newInstance();
we can create instances of classes that are not known at compile time. I use this trick all the time to add functionality to a system without having to change the core classes. I pass in a new classname in a string and it creates an instance and uses it.
Note that this code requires the instance to implement MyInterface. If I mess up and pass the name of a class that does not implement MyInterface, this will throw a cast exception.