jeudi 12 février 2015

Abstract classes share properties, any way to put them in one place?

I have two abstract classes that has couple of same properties. How can I put them in just one common place?



public abstract class ClassA
{
public abstract string PropertyA {get; }
public abstract string PropertyB {get; }
public string PropertyX {get; set;}
}


public abstract class ClassB
{
public abstract string PropertyA {get; }
public abstract string PropertyB {get; }
public string PropertyY {get; set;}
}

public class ClassC1 : ClassA
{
public string PropertyA {get {return "MyString";} }
public string PropertyB {get{return "MyOtherString";} }

}

public class ClassC2 : ClassA
{
public string PropertyA {get {return "MyString2";} }
public string PropertyB {get{return "MyOtherString2";} }

}

public class ClassD1 : ClassB
{
public string PropertyA {get {return "MyString";} }
public string PropertyB {get{return "MyOtherString";} }
}

public class ClassD2 : ClassB
{
public string PropertyA {get {return "MyString2";} }
public string PropertyB {get{return "MyOtherString2";} }
}


This is my scenario. Now since PropertyA and PropertyB returns the same value for both class, I was wondering if there's any way I can refactor the classes so I don't have put the same properties in both abstract/concrete classes.


Aucun commentaire:

Enregistrer un commentaire