Best way to refactor common code
c#
Solution
Try this solution: all properties at `Sample` class will be `virtual`, if you want to decorate some of them at derrived classes with attributes, just `override` them.
public class Sample
{
public virtual int x { get; set; }
public virtual string y { get; set; }
}
public class SampleA : Sample
{
}
public class SampleB : Sample
{
[Decorated]
public override string y { get; set; }
}
Problem
Consider the following two classes that implements a bunch of properties from an interface: Interface code: ``` public interface ISample { int x; string y; } ``` Class 1: ``` public class SampleA: ISample { public int x { get; set; } public string y { get; set; } } ``` Class 2: ``` public class SampleB: ISample { public int x { get; set; } [Decorated] public string y { get; set; } } ``` Only difference here being is that `SampleB` has one property decorated with an attribute. This is highly simplified and the classes in question have many more properties but the main differences being one class has some properties decorated with attributes. There will be situations in the future where further classes will be introduced that implement the `ISample` interface and feel as though these classes should probably inherit some common code maybe from an abstract class or something. What would be a good approach to refactor this code?