简体   繁体   中英

Bringing together functionality and e.g. ComboBoxes - Are there any solutions / code existing? (exept binding)

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 eg between CRC16 or CRC32 if ICRCxx has been passed through IStrategy. Operator is eg 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 eg "ORM", "IQToolKit", ... for connecting OleDb to OOCode. In my case I want to connect functionality with eg ComboBoxes.)

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM