Reputation: 299
I have 2 different types of input. I prompt an alert window for users to select which type of input they want my system to process.
Let's say 1st type of input is: 1,2,3 and 2nd one is a,b,c
But, both need the same generator.class. I want to make it in a same GUI class. Currently I have GUI for 1st input.
Is it OK? How to do it?
Upvotes: 0
Views: 131
Reputation: 35598
You have a couple of different ways to do this and without knowing more about how you process input, it's difficult to tell you how I would do it. You could either use the Factory Pattern as @Dan suggests, or you could use the Strategy Pattern with two different strategies (one for numeric input, another for alphabetical input) with the selection of which one to use made based on user input. Based on what you've told us, I could see either working, but I have a feeling one will be better than the other based on the way your system is designed.
Upvotes: 0