How do you write code whose logic is protected against future additional enumerations?

后端 未结 10 1530
旧巷少年郎
旧巷少年郎 2021-02-05 08:01

I\'m having a hard time describing this problem. Maybe that\'s why I\'m having a hard time finding a good solution (the words just aren\'t cooperating). Let me explain via cod

10条回答
  •  醉梦人生
    2021-02-05 09:02

    While I don't have a ton of C# experience, were this Java, what I would instead do is create an interface IPeelable and another ICoreable, and have the fruit classes implement those. Then, instead of avoiding not logic, you could simply check to see if the fruit you've gotten implements either of the interfaces -- in this way, you can add future fruits which implement both peelable and coreable, like the muskmelon.

提交回复
热议问题