Looking over a code I found something similar to this:
public class Ford
{
...
public int Power { get; set; }
}
public class Dacia
{
...
public int Power { get; set; }
}
public class FordModel
{
...
public int CarForce { get; set; }
}
public class DaciaModel
{
...
public int CarForce { get; set; }
}
From the naming perspective, we have two different names of the properties that has the same naming. Because of this we can be misunderstood and developer will need to look twice to understand what the hall is there.public class Ford
{
...
public int Power { get; set; }
}
public class Dacia
{
...
public int Power { get; set; }
}
public class FordModel
{
...
public int CarPower { get; set; }
}
public class DaciaModel
{
...
public int CarPower { get; set; }
}
Now is better, but there is still a problem. Looking over the Ford and Dacia class we notice that there is a common property that define a Car. In this case we should have an interface or a base class with the items that are common.public abstract class Car
{
...
public int Power { get; set; }
}
public class Ford : Car
{
...
}
public class Dacia : Car
{
...
}
I would go on an interface that define the power concept of a car and on an abstract class that add this on the Car definition.
public interface IPower
{
int Power { get; }
}
public abstract class Car : IPower
{
...
public int Power { get; set; }
}
public class Ford : Car
{
...
}
public class Dacia : Car
{
...
}
In this way we will be able to specify what are the items that have the power attribute.
Comments
Post a Comment