Reputation: 2905
So, I have 3 fields/properties. Say, they are, paramA, paramB, paramC. And I’ve three classes as Class A, Class B, Class C.
Requirement is to use:
• paramA, paramB in Class A
• paramA, paramC in Class B
• paramB, paramC in Class D
Is there any way to declare all these 3 properties in a common place and derive in the A,B,C classes as per the requirement....?
UPDATE
Please find some more details of the requirement:
The real requirement is:
There is a table ‘Que Table’ in database which is having following fields
• bool IsQb
• bool IsOverride
• string Identifier
• string userlogin
• FolderName
Following model classes are using for create/update/delete data in ‘Que Table’.
• CreateQue class
• UpdateQue class
• DeleteQue class
CreateQue class only requires the properties:IsQb, IsOverride,UserLogin, FolderName
UpdateQue class only requires the properties: IsQb, IsOverride, Identifier, UserLogin, FolderName
And DeleteQue class only requires: Identifier property.
The code for the model classes are:
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; }
}
So, is there any pattern/architecture out there to declare all those properties in a single place and derive as per the requirement in those model classes....?
Thanks in advance
Upvotes: 0
Views: 51
Reputation: 151720
It's a bit unclear what you need to do as we can't see your requirements. You could use interfaces:
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; }
}
Upvotes: 4