If interface A and classes B and C are in the library, and your code is the main method that uses the library, that means classes D , E , etc. can be added to libraries, and you can use them without changing the code. The responsibility for choosing which implementation to use is transferred to the library.
In addition, your example is extremely simple. In other cases, input can be more complex than a string that exactly matches the type. The input may be a file with a specific format, which requires, for example, reading a specific version.
source share