The creation can be delegated to a factory class. IF you have different sets for implementation types, then an abstract factory. So there is the pattern.
I am not sure if those if blocks are just an example, but they can be optimized, for example moving if(Y.isExists) to an upper block.