Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 这是简化继承类的有效方法吗?_C#_Azure_Azure Storage_Azure Table Storage - Fatal编程技术网

C# 这是简化继承类的有效方法吗?

C# 这是简化继承类的有效方法吗?,c#,azure,azure-storage,azure-table-storage,C#,Azure,Azure Storage,Azure Table Storage,我有许多Azure类,其中包含日期字段,并通过跟踪进行修改。字段,例如: [DisplayName("Created By")] public string CreatedBy { get; set; } [DisplayName("Modified By")] public string ModifiedBy { get; set; } 我希望避免重复,因此我考虑创建一个类来包含以下内容: public class TableServiceEntityRowInfo : TableServi

我有许多Azure类,其中包含日期字段,并通过跟踪进行修改。字段,例如:

[DisplayName("Created By")]
public string CreatedBy { get; set; }
[DisplayName("Modified By")]
public string ModifiedBy { get; set; }
我希望避免重复,因此我考虑创建一个类来包含以下内容:

public class TableServiceEntityRowInfo : TableServiceEntity  
{
    [DisplayName("Created By")]
    public string CreatedBy { get; set; }
    [DisplayName("Modified By")]
    public string ModifiedBy { get; set; }
}
对于我的数据类,与其让它们从TableServiceEntity继承,不如按如下方式进行设置:

public class MyClass : TableServiceEntityRowInfo 
{

}

这是向字段添加附加信息的有效且合理的方法。我在这里问这个问题的原因是因为我计划对很多课程都这样做,我想确保我做了正确的事情。

是的,这是有效和明智的

如果有任何关于Azure的具体问题,我无法回答

至于关于“是一个”和“有一个”的评论,我认为这里可以完全忽略它。实际上,这几乎可以归结为命名风格。您将基类命名为
TableServiceEntityRowInfo
,因为它是一个具有行信息的
TableServiceEntity
。如果改为调用它
AuditableTableServiceEntity
,因为它有用于审核的字段,该怎么办。现在它是完全相同的,但是您可以声明每个继承类“都是一个”
AuditableTableServiceEntity


您可能还希望将基类标记为
abstract
,以明确它不应该被实例化,而应该被继承。

我不是100岁,但一般来说,如果类“是”父类,我会尝试继承。在您的情况下,它们听起来更像是“HAS a”,在这种情况下,我可能会将相关属性分组到一个单独的类中,并在需要此功能的类上公开该属性,即MyClass有一个名为EntityRowInfo的属性,其中包含您的ModifiedBy、CreatedBy属性。我非常喜欢命名和关于抽象的注释。非常感谢。这将在Azure中正常工作,因为您的类继承自的TableServiceEntity只是一个非常基本的类,具有RowKey、PartitionKey和Timestamp属性。