IAdjustSpeed
public class Treadmill : IAdjustSpeed
{
public void Accelerate(double rate, TimeSpan duration)
{
// Implementation body
}
public void Decelerate(double rate, TimeSpan duration)
{
// Implementation body
}
public double CurrentSpeed { get; private set; }
}
IAdjustSpeed
public class Car : IAdjustSpeed
{
public void Accelerate(double rate, TimeSpan duration)
{
// Implementation body
}
public void Decelerate(double rate, TimeSpan duration)
{
// Implementation body
}
public double CurrentSpeed { get; set; }
}
IAdjustSpeed
public class Elevator : IAdjustSpeed
{
public void Accelerate(double rate, TimeSpan duration)
{
// Implementation body
}
public void Decelerate(double rate, TimeSpan duration)
{
// Implementation body
}
public double CurrentSpeed { get; set; }
}
IAdjustSpeed
public class ControlPanel
{
private IAdjustSpeed _ControlledItem;
public ControlPanel(IAdjustSpeed obj)
{
_ControlledItem = obj;
}
public void HandleKeypress(char key)
{
switch(key)
{
case "w":
_ControlledItem.Accelerate(boostRate, new TimeSpan(0, 0, 5));
break;
// ...
}
}
}
ILocatable
IPingable
Adapted from an old text-based Star Trek game
public interface ILocatable
{
Location QuadrantPosition { get; }
Location SectorPosition { get; }
Quadrant Quadrant { get; }
Sector Sector { get; }
}
public interface IPingable
{
string Ping();
}
public class Star : AbstractLocatable
{
public string ping() {
return " * ";
}
}
public class Space : IPingable
{
public string ping() {
return " ";
}
}
> **Dependency Inversion Principle** > > - Depend on abstractions, not on concretions TODO: - Interfaces in .Net Core