This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public sealed class Golfer | |
: IDriver | |
{ | |
public void Drive() | |
{ | |
var value = RandomNumberGenerator.GetInt32(250, 320); | |
Console.WriteLine($"{value} yards"); | |
} | |
public override void Stop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class Driver | |
{ | |
protected Driver() { } | |
public abstract void Drive(); | |
public virtual void Stop() { } | |
} | |
public sealed class GolferDriver |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ModernGolfer | |
: IModernDriver<ModernGolfer> | |
{ | |
public static void Drive(IEnumerable<ModernGolfer> modernGolfers) | |
{ | |
foreach(var modernGolfer in modernGolfers) | |
{ | |
modernGolfer.Drive(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IModernDriver<TSelf> | |
where TSelf : IModernDriver<TSelf> | |
{ | |
static abstract void Drive(IEnumerable<TSelf> modernDrivers); | |
void Drive(); | |
void Stop() { } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IDriver | |
{ | |
public static void Drive(IEnumerable<IDriver> drivers) | |
{ | |
foreach(var driver in drivers) | |
{ | |
driver.Drive(); | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IDriver | |
{ | |
void Drive(); | |
void Stop(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IDriver | |
{ | |
void Drive(); | |
void Stop() { } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
287 yards | |
177 MPH |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void Drive(IEnumerable<IDriver> drivers) | |
{ | |
foreach(var driver in drivers) | |
{ | |
driver.Drive(); | |
} | |
} | |
Drive(new IDriver[] { new Golfer(), new Racer() }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public sealed class Golfer | |
: IDriver | |
{ | |
public void Drive() | |
{ | |
var value = RandomNumberGenerator.GetInt32(250, 320); | |
Console.WriteLine($"{value} yards"); | |
} | |
} |
NewerOlder