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

后端 未结 10 1569
旧巷少年郎
旧巷少年郎 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:35

    Use the social factor!

    enum Fruit
    { 
        Apple,
        Orange,
        Banana,
        // add Grape here, and I'll shoot you
        // not kidding.
    }
    

    With me it would work (i.e. make me study the application's inner design deep enough not to introduce changes based on "lightweight" assumptions only) :))

提交回复
热议问题