I am developing for two operating systems. Each has a specific implementation of BaseClass
. I would like to abstract these implementations. My idea is to use an interface both of the implementations implement and then return the OS specific class using the factory pattern. This would look similar to this.
However taking this approach would need me to specify which implementation should be used before building the application, e.g. by a constant variable holding the name of the OS (platform
variable in the linked answer). This seems to be a bad design choice to me.
Is there another way to define which OS to build for?