Calling a unique function based on matrix row and col index
There are three views
ViewA
ViewB
ViewC
a user can switch from ViewX to ViewY. There is a different way to switch from X and Y. e.g. Switching from A to B is through one way while from B to A will be through some different way.
I am trying to write a generic function for it. As I can understand, these three views makes a total of 6 combinations (A-B, A-C, B-A, B-C, C-A, C-B)
ViewA ViewB ViewC
ViewA X 2 3
ViewB 4 X 6
ViewC 7 8 X
What I am thinking that I will register specific function to given move. e.g. if move is from ViewA to ViewB then I will register function SwitchViewA_to_viewB() to the 2nd index.
Please let me know if we can have some other better approach to achive it. This is just an example with three view. In my actual case, I have almost 10 such views.
It’s called a dispatch table.
or
Note that you can pass arguments to the function by passing them within the parens (as usual).
If you have 10 views, that means to say you have 90 functions.
Are you sure that’s the way to you want to approach this issue? You should perhaps consider an approach that doesn’t require knowing the previous view. Perhaps you can have two functions per view. One that’s called to activate the view, and another to deactivate it.
Then you only need to 20 functions instead of 90. And adding an eleventh view would only require writing 2 functions instead of 20.