I'm running into my least favorite problem, and that is rewriting code. Here is the structure I have currently designed.
public interface ICanMove
{
int speed { get; set; }
void Walk();
void Run();
}
public class Worker : ICanMove
{
speed = 5;
public void Walk()
{
//Example code Move(speed);
}
}
public class Warrior : ICanMove
{
speed = 3;
public void Walk()
{
//Example code Move(speed);
}
}
The problem here is multiple classes use the interface the same way. But they won't always do it the same way. Is there a way to implement this..more correctly. The other option i have is an abstract class which would work for this example, but not when I have even more interfaces(ICanAttack,ICanBuild)
With abstract class
public abstract class LivingCreature : ICanMove
{
public abstract int speed {get;set;}
public void Walk()
{
//Example code Move(speed);
}
public void Run()
{
}
}
But then my problem becomes I have to implement multiple interfaces on a base class which not every object that inherits from that base class will need 100%