- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我明白 C# 中没有多重继承。但是,我遇到了一种我真的希望它存在的情况。我正在创建一个自定义类,它需要我从 CLR 类型继承并覆盖一些方法。不幸的是,我正在创建其中几个非常相似的。为了 DRY,我真的很想将通用功能移动到基类,但我需要从 2 个类继承。我可以使用接口(interface)(事实上我现在正在使用一个接口(interface))但这只解决了一半的问题,因为方法实现仍然需要在多个自定义类中重复。
实现我想要做的事情的最纯粹的方法是什么?
编辑:
这是一个通用的代码示例
public class CustomTypeOne : CLRType
{
public override void Execute(HttpContext context)
{
//Some code that's similar across CustomTypeOne, CustomTypeTwo etc
}
public void DoStuff()
{
//Same for all CustomTypes and can be part of a base class
}
//More methods
}
public class CustomTypeTwo : CLRType
{
public override void Execute(HttpContext context)
{
//Some code that's similar across CustomTypeOne, CustomTypeTwo etc
}
public void DoStuff()
{
//Same for all CustomTypes and can be part of a base class
}
//More methods
}
最佳答案
有时我觉得多重继承可以挽救局面,但我意识到它确实使实现和可维护性更具挑战性。 MI 在继承的类中有效地合并了公共(public)和 protected 命名空间,这可能会导致一些您不需要的歧义和复杂性。
关于c# - C# : What is the purist way of achieving what I am trying to do? 中的多重继承,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3195786/
这个问题在这里已经有了答案: 关闭 11 年前。 Possible Duplicate: How do short URLs services work? 我经常看到来自 bitly.com 的缩短
我编写了一个简单的游戏,并希望将 GameCenter Achievements 与其集成。 我想尝试以一种干净整洁的方式来做到这一点,这样很容易添加额外的成就。 在我看来,成就包含以下内容: 触发器
我在 Dribble 中发现了一些 Appbar 设计 https://dribbble.com/shots/9175650-Beauty-Salon-App/attachments/1218583?
我有这样的东西。 function a() { ajax(callback_function); } callback_function() { // done!, called after
我有三列布局。在第三列中,我有两个 div。第一个 div 是固定的。第二个 div 的最小高度为 50px。当第二个 div 中的文本内容增加时,它的高度应该增加到到达第三列底部的点,然后它应该显示
我正在尝试分析/分析核心 JAVA 应用程序。 我正在使用 JConsole Eclipse MAT 。 我在 Perm-Gen 图表中观察到以下情况(在 Windows XP 计算机上记录的 1 小
我有一个按钮附加到父按钮: var parent_button = document.createElement("button"); var child_button = document.crea
在 jquery 中的 div 之间链接动态事件的最佳方法是什么。 我的 HTML 页面: 对于每个点击的 parent ,我想切换它的 child Example :: if p
上下文: 我在阅读 Pomakis 的哈希表实现时出现了一个问题。 Hash lookup 我经常使用 Startpage 来查找更多信息,但仍然一头雾水。 问题: 因为它使用链表来检索 key ,怎
我在想什么 InstrumentationInfo#functionalTest应该实现。对应用环境的启动方式有影响吗? 最佳答案 我在 Android 问题跟踪器上问了这个问题(不幸的是我再也找不到
模偏差是天真地使用模运算来获得小于给定“上限”的伪随机数时出现的问题。 因此,作为一名 C 程序员,我正在使用 arc4random_uniform() 函数的修改版本来生成均匀分布的伪随机数。 问题
我有一个 3 节点 Cassandra 集群,其 key 空间的复制因子为 3: CREATE KEYSPACE demo WITH REPLICATION = { 'class':'Si
元素 tasklist最多可以包含一个 title最多一个 description ,另外任何数字(包括 0)task任何顺序的元素。 天真的方法不适用,因为顺序无关紧要: 或者,我可以明确命名所有
目前,我使用 Azure 服务总线作为平台中不同服务之间的通信和保持数据一致性的手段。但是,假设我的一项服务(订阅者)长时间停机并且无法接收任何事件。突然间,该服务处于不一致的状态。 Azure 服务
我有以下字典: res = [{'name': 'mfi', 'percentage': 100.0, 'tax_base': 1000.0, 'tax_amount': 140.0}, {'name
我有以下字典: res = [{'name': 'mfi', 'percentage': 100.0, 'tax_base': 1000.0, 'tax_amount': 140.0}, {'name
我有两个文件。我正在尝试查找与特定人相关的所有论文。文档保存在它们的集合中,并且正在创建从 Person 到 Paper 的引用,但不是相反。 /** @ODM\Document */ class P
请问有人可以帮我解决 jquery Slider 范围问题吗?我是 jQuery 新手,试图在左/右拖动范围内实现 min(右箭头图标)和 max(左箭头图标)。 价格范围:0 - 1000==(>)
//lets get the auto name set $accepted = 0; $sql = mysql_query("SELECT * FROM ".TBL_FACTIONS." WHERE
我目前正在尝试将大量 XML 更改为 Java 对象,但我一直陷入困境。我尝试过在线复制很多不同的示例,但我似乎永远无法找到正确的方法,而且我发现调试起来非常困难。 我的 XML 看起来像这样
我是一名优秀的程序员,十分优秀!