Better way to call overloaded functions with more-derived parameters, passing in less-derived types

后端 未结 2 1636
予麋鹿
予麋鹿 2021-01-28 09:58

I have 16 methods that take two parameters, and each of the two parameters can be either an \'Insertion\' or a \'Deletion\', both of which implement IFragment. I also have four

2条回答
  •  不思量自难忘°
    2021-01-28 10:34

    First of all, you can't call a method with objects that are "less derived" since the method you are calling is waiting for a minimum requirements from this type.

    For this type of problem, I think it's better just using different names for that function. "IntroduceAntecedent" should exist along with "IntroduceAntecedent_DelDel" and all 3 other combinaisons. That's clearly my own opinion, but The way you did it seems ok for what you would expect it to do.

提交回复
热议问题