0

I suppose I have got a design problem. So lets start from the beginning. This is what I want:

On one side there are ComboBoxes, which need to be filled, letting the user choose between functionality provided. On the other side this functionality has to be called, to fulfill its purpose.

I was thinking about something like this, scattered somewhere in the GUI:

// Parameter type describes what to do. This example shows that a CRC value 
// shall be calculated. But it could be a quadratic formular or any other // calculation as well. So I assume parameter is of type IStrategy.
// And here I assume a further interface exist, lets say ICRCxx.
ChoiceProvider functionality = new ChoiceProvider(CRC16);

// Yes, I know about Items and binding. Method returns functionality
// provided by ICRCxx. For example just { "CRC32", "CRC16 CCITT" } will be 
// returned at the moment.
string[] cellChoice_Of1stComboBox = functionality.GetCalculationNames();
bool functionality.SetCalculationName(string name);

// Here between start values can be chosen, necessary for the calculation.
// For example { "Ox0000", "Ox1D0F" } will be returned, if "CRC16 CCITT"
// has been selected above.
string[] cellChoice_Of2ndComboBox = functionality.GetCalculationVariants();
bool functionality.SetCalculationVariant(string name);

// to be displayed somewhere on GUI
string userResult = functionality.GetUserResult(); 

// Return type may vary depending on chosen calculation within.
var processResult = functionality.GetProcessResult(); 

// This is just a idea to be able to handle processResult.
// Maybe you have got a better idea. About that I had a struggle with
// generics.
Type processResultType = functionality.GetProcessType(); 

I am sorry, a lot of words will still follow.

I already got a class called ChoiceProvider. I made it generic, because first I tried it with recursion, to be able to combine as much ComboBoxes as I want. It is based on an dictionary>, as I am working with names. And T within IChoice>T> could be any kind of calculation.

ChoiceProvider is already working within an visitor pattern, being there the operator. But I failed let it work recursively before (without pattern).

Below visitor pattern (visited is TChoice, visitors are of IStrategy) is a strategy pattern to choose e.g. between CRC16 or CRC32 if ICRCxx has been passed through IStrategy. Operator is e.g. collecting calculations offered, so if ICRCxx has been passed, concrete strategy classes CRC16 and CRC32 will be collected as possible ComboBox choices.

But when passing data between methods Visit(IVisited... ) from class Do_Strategy (meaning "do calculate") to class Get_ProcessResult, I struggeled with generics as mentioned above. As I am not an expert with generics.

First I thought to ask you about my problem passing data from one class to another, struggling with generics or with something like this: How to force derived class to implement a static property or field?

But then I realized, that I could not find to a good question to find the right answer (technically or by design). So now I will just ask you about the design.

I now think visitor pattern makes it probably too complicated. I now think about just a main strategy pattern and a second strategy pattern below. But I wasted time. And I would like to be on a got path before I start with something new again. So I ask you.

...


Update - making it short:

Visitor pattern in my eyes, in my case is not the right way to go. I would like less code and more scalable.

I tried it with what I call a "closed functionality wired with GUI" (see above). Usually I get code where functionality and GUI are mixed up, where I have to find open functionality somewhere spread in the GUI.

  • Are there already any simple solutions/code existing for my "closed purpose"?
  • Are there useful keywords about which I should now? (like e.g. "ORM", "IQToolKit", ... for connecting OleDb to OOCode. In my case I want to connect functionality with e.g. ComboBoxes.)
B. Ernst
  • 25
  • 4
  • Such questions are a bit too broad for SO. Perhaps [software engineering](https://softwareengineering.stackexchange.com/) is a better place? – Sinatr Jul 26 '19 at 10:05
  • How can I move my question then to software engineering? Is there a simple click or do I have to rewrite it again? – B. Ernst Jul 26 '19 at 11:01
  • You need to flag question for moderator attention, see [here](https://meta.stackexchange.com/q/85017/299295). But I am not really sure if it fits as it is, you may need to work on question first. Please read their [help](https://softwareengineering.stackexchange.com/help) (namely what to ask and what not to ask). – Sinatr Jul 26 '19 at 11:19

2 Answers2

0

My feeling is that you try to do something quite simple in an extremely complicated way.

Are you trying to populate ComboBoxes dynamically depending on choices? Example.. You select in ´ComboBoxFunctionSelector` the value "CRC16" and when it was selected, you want to pick up this value immediately, and call a method of a class with it as a parameter like MySuperCalculator.SetMode("CRC16"). And in return you are getting back some sets of parameters to update all other ComboBoxes with them?

Or you want to pack the choices of all comboboxes to a class and get back the results based on the parameters in the package?

Dogmeat
  • 7
  • 4
  • Its the second. I want give comboboxes choices (string[]) depending on strategies/classes I have got to calculate something. User shall chose one of those strings (by combobox), calculation just needs to be started. And, of cause, in the background result of this calculation will be of some other type than string, to be used. – B. Ernst Aug 05 '19 at 06:19
  • Actually its to separate GUI code from functionality. That is why I don't work with comboboxes and use strings instead. Comboboxes are just where those strings will go to (and from where they will come back). – B. Ernst Aug 05 '19 at 06:28
  • I would solve this with message classes. Based on selected function you set the properties of the specific function class (like for example CRC16_Message) than simpy call the calculator with the object as the parameter. In the calculator, you add an overload for each different message type. (Like MyCalculator.Calculate(CRC16_Message)) – Dogmeat Aug 05 '19 at 21:10
0

I solved this by something like a command pattern (as it stores previous steps done/strategies used).

But instead of commands (containing receiver and its config) its storing strategies of strategy pattern below. Invoker class is getting context class via constructor, which will never change as long as invoker class exist.

B. Ernst
  • 25
  • 4