Where to put common interface methods when dealing with partial classes, inheritance, and Visual Studio Generated Code

前端 未结 2 1338
悲&欢浪女
悲&欢浪女 2021-01-16 21:20

Consider this situation:

We have two classes generated by Visual Studio, for example Typed Dataset Rows. These classes derive from a common base class which we can

2条回答
  •  天涯浪人
    2021-01-16 21:35

    I would use encapsulation in this case. Create a class (with a private instance in both classes), and delegate the SomeMethod call to the internal, private class implementation.

    This eliminates (most) of the duplication, while still allowing the benefits of unique implementations per class as necessary.

提交回复
热议问题