Below I have a Person interface, an implementing class and a driver class which initialises the Person with a name and just outputs it again. What is the advantage of using
One advantage I can think of is that you might have 2 very different types of people, but you want to wait until runtime (based on user input, config file, etc.) to decide which one to use. You can do something like this:
Person person = null;
if ...
person = new PersonImpl();
else
person = new PersonImpl2();