How to implement alternative items. A is alt. to B and C => B alt. to A and C, etc.
How is this usually designed? An item with alternative items. For example B is alternative to A. That means A is alternative to B too. If I create C alternative to A, A and B become alternatives to C. Each one is an alternative to each other.
Now imagine you have a tab for each (A, B, C) where you have the rows of alternatives.
A Sync service has to update each tab when an alternative is added anywhere in the tabs.
How would you implement this at the db or object level?
18 Replies
I'm not entirely sure what you mean by "Alternative Item".
But it sounds a bit like you need an abstract base class and then handle each inheriting type individually on the UI level.
In the database you can just use a "table per hierarchy mapping". If you use EFCore it can handle that for you and there is a lot of documentation out there on how to do that.
C# Online Compiler | .NET Fiddle
Test your C# code online with .NET Fiddle code editor.
This is what it was designed by someone else. I proposed to my PM a simpler solution. Initially I was ignored and now the whole thing got to complicated. Looking forward to see what other people have in mind, without clouding them with my solution.
So alternatives always go both ways?
yes
Is the path of interest?
What I mean is, do you need to know that A is an alternative to C, because both are an alternative to B?
Yes. Each item needs to have complete list of alternatives, so every new alternative item added, the synchronization needs to be done again and add in each item the new alternative
That didn't answer the question.
Do you just need to know that A is an alternative to C, or is the information important that A is an alternative to C, because both are alternatives to B.
Basically is there a difference between something being a direct alternative or indirect one.
No, I just need to know that A is an alternative to C
If I add D as alternative to A, D will be alternative to all. Is not important in the UI why. I just need to list/print the alternatives of each.
each item has its own tab with a grid where all alternatives for that item is listed
Then what is the problem with stuffing them all into a simple list?
like in my example?
the problem is if I add D to the list of A, that D needs to be added to the rest of the items.Alternatives
you have to check each item where A is an alternative and add D and to D add the item that you just checked
No just have a single list containing A B and C.
And if D comes into the mix add it to that single list
and each item would have an id that points to that list?
what I proposed is grouping, because this is esentially groups
C# Online Compiler | .NET Fiddle
Test your C# code online with .NET Fiddle code editor.
Yes you could do that
assign a groupId to the ones you want to be alternatives and done
Unless you need to recalculate the groups often that also works fine. (If it's all stored in a DB that's less of a concern)
yes, is in the DB, but is loaded in the memory (UI) and if a new item is added in any alternative group, is tracked and saved separately.
but with a group or a list like you said, is way simpler than the current implementation