我写了一个楼主画的TabControl
,但是我们的项目也使用了TabWorkspace
其源自TabControl
。此刻,我有
public class OurTabControl : TabControl
{
// some code that overrides protected methods
}
public class OurTabWorkspace : TabWorkspace
{
// the same code
}
我希望共享代码只出现在一处,这样我们就不必维护两份副本。这在 C# 中可能吗?如果可以,如何实现?
您可以使用接口并编写扩展方法来完成此操作。
class OurTabControl: IBehavior
class OurTabWorkspace: IBehavior
interface IBehavior
{
}
static class BehaviorExtensions
{
static [returntype] RepeatedBehavior(this IBehavior behavior)
{
//repeated code here
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)