I have lots of class who inherit abstract class and many interface. but problem is class should implement members declared in interface. so I should type lots of duplicate code.
I think that violates OOP's DRY principle, So I tried many things but below is my best.
Is there any way better than mine?
Current
public interface InterfaceWithProperties
{
public int IntegerProperty { get; set; }
public string StringProperty { get; set; }
}
public abstract class AbstractClass1
{
public abstract Guid GuidProperty1;
}
public abstract class AbstractClass2
{
public abstract Guid GuidProperty2;
}
public sealed class DerivativeClass1 : AbstractClass1, InterfaceWithProperties
{
[TargetAttribute(ValueForDerivativeClass1)] public override Guid GuidProperty1 { get; set; }
[SomeAttribute] public int IntegerProperty { get; set; }
[SomeAttribute] public string StringProperty { get; set; }
}
public sealed class DerivativeClass2 : AbstractClass2, InterfaceWithProperties
{
[TargetAttribute(ValueForDerivativeClass2)] public override GuidProperty2 { get; set; }
[SomeAttribute] public int IntegerProperty { get; set; }
[SomeAttribute] public string StringProperty { get; set; }
}
There could be a lot of sealed derivative class with different base class but same interface. so below parts duplicate many times
{
[SomeAttribute] public int IntegerProperty { get; set; }
[SomeAttribute] public string StringProperty { get; set; }
}
So Is There a way to declare this part of code for my purpose?
for example I imagine some "augmentation" type achieve like this.
public augmentation AugmentationWithProperties : InterfaceWithProperties
{
[SomeAttribute] public int IntegerProperty { get; set; }
[SomeAttribute] public string StringProperty { get; set; }
}
so now derivative classes look like these
public sealed class DerivativeClass1 : AbstractClass1, AugmentationWithProperties
{
[TargetAttribute(ValueForDerivativeClass1)] public override Guid GuidProperty1 { get; set; }
}
public sealed class DerivativeClass2 : AbstractClass2, AugmentationWithProperties
{
[TargetAttribute(ValueForDerivativeClass2)] public override Guid GuidProperty2 { get; set; }
}
Is There a Way to achieve this?
Please Give me your advice, Thank you.