interface IEntity { // interface representing an entity in a game world
Vector3 Position { get; }
}
interface ISoundEmittingEntity : IEntity { // represents any entity that emits sound
float SoundRadius { get; }
// method with a default (sensible) implementation; can be overridden for more complex cases
bool IsAudibleToPlayer(Player player) => Vector3.Distance(player.Position, Position) <= SoundRadius;
}
class Rocket : ISoundEmittingEntity {
public Vector3 Position { get; private set; }
public float SoundRadius { get; } = Units.InMetres(4f);
}
// ----
void SomeMethod(Rocket rocket) {
if (rocket.IsAudibleToPlayer()) PlaySound(Sounds.RocketSound);
}
Code snippet taken from "C# 8 Concerns".