What are the dangers of making a method virtual?

前端 未结 3 1427
离开以前
离开以前 2021-01-12 11:47

I\'ve been doing some mocking with RhinoMocks and it requires that mocked methods be made virtual. This is fine except we have a custom framework which contains the methods

3条回答
  •  礼貌的吻别
    2021-01-12 12:13

    • If you have users that override your virtual methods you can't seal them again without breaking code.
    • Any virtual methods you call from the constructor may fall down to derived implementations and if they don't call the base method and the constructor depends on it, the object may be in an invalid state

提交回复
热议问题