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

后端 未结 10 1558
旧巷少年郎
旧巷少年郎 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 08:49

    I would use types, not enums, for the data structures... E.G. Create an interface IFruit that has the following:

    interface IFruit
    {
         bool NeedsCoring();
         void GetEaten(Person by);
         // etc.
    }
    

    And then I would just call the methods already there for determining whether it needs to be cored or whatnot.

提交回复
热议问题