I have an Interface lets say ISendOut which I’ve inherited two different classes from it
for example TransferViaSerialPort and TransferViaWirelessModule (I mean implement this Interface in these two classes). How can I design my software to both giving the ability to the user to choose (IN THE UI) between the methods of sending his/her data out via SerialPort or WirelessModule and not violate the OCP? Because if I want to have a “Switch Case” or an “If/Else” statement I will Violate the OCP.
I have an Interface lets say ISendOut which I’ve inherited two different classes from
Share
You need to use the Factory Pattern. And to make the Factory Pattern dynamic you can use Reflection and to show the Types of your Classes in the
UIwhich are Implemented fromISendOutyou can use Custom Attributes or other methods like using aDictionary.Later I add UsbSendOut without modifying existing code (so not Breaking the OCP)