根据要求得出属性......?

时间:2015-02-26 09:26:01

标签: c# design-patterns

所以,我有3个字段/属性。说,他们是,paramA,paramB,paramC。我有三个班级,如A班,B班,C班 要求是使用:

•   paramA, paramB in Class A
•   paramA, paramC in Class B
•   paramB, paramC in Class D

有没有办法在公共场所声明所有这3个属性,并根据要求派生出A,B,C类....?

更新

请查看有关要求的更多细节:
真正的要求是: 数据库中有一个表'Que Table',其中包含以下字段

•   bool IsQb
•   bool IsOverride
•   string Identifier
•   string userlogin
•   FolderName

以下模型类用于“Que Table”中的创建/更新/删除数据。

•   CreateQue class
•   UpdateQue class 
•   DeleteQue class

CreateQue类只需要属性:IsQb,IsOverride,UserLogin,FolderName
UpdateQue类只需要以下属性:IsQb,IsOverride,Identifier,UserLogin,FolderName
而DeleteQue类只需要:Identifier属性。

模型类的代码是:

public class CreateQue 
    {
        public bool IsQb { get; set; }
        public bool IsOverride { get; set; }
        public string  userlogin { get; set; }
        public string FolderName { get; set; }
    }

    public class UpdateQue
    {
        public bool IsQb { get; set; }
        public bool IsOverride { get; set; }
        public string Identifier { get; set; }
        public string userlogin { get; set; }
        public string FolderName { get; set; }
    }

    public class DeleteQue
    {
        public string userlogin { get; set; }
        public string Identifier { get; set; }
    }

那么,是否有任何模式/体系结构可以在一个地方声明所有这些属性,并根据这些模型类中的要求派生出来?
提前致谢

1 个答案:

答案 0 :(得分:4)

由于我们看不到您的要求,您需要做什么有点不清楚。你可以使用接口:

public interface IHasPropertyA
{
    string PropertyA { get; set; }
}

public interface IHasPropertyB
{
    string PropertyB { get; set; }
}

public class ClassA : IHasPropertyA, IHasPropertyB
{
    public string PropertyA { get; set; }
    public string PropertyB { get; set; }
}