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. IStrategy lets choose between e.g. ICRCxx and IQuadraticFormular) is a strategy pattern to choose e.g. between CRC16 or CRC32.
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.
And here is where I am standing now. 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.
- Do you have got a much simpler solution or approach?
- Is there already some code existing, which could be useful for me?
- Is there a useful subject about which I should now? (If so please give me the right keyword)
- What do you think about visitor pattern, is this the right place for it?
Aucun commentaire:
Enregistrer un commentaire