Skip to content

Instantly share code, notes, and snippets.

@configureappio
Created January 19, 2020 13:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save configureappio/bb5ad50704820242935c49c468f752d0 to your computer and use it in GitHub Desktop.
Save configureappio/bb5ad50704820242935c49c468f752d0 to your computer and use it in GitHub Desktop.
Interface and implementations to map temperature scales to Kelvin scale
private interface IKelvinMapper
{
decimal ToKelvins(decimal value);
}
private class CentigradeToKelvinMapper : IKelvinMapper
{
public decimal ToKelvins(decimal value) => value + 273.15M;
}
private class FahrenheitToKelvinMapper : IKelvinMapper
{
public decimal ToKelvins(decimal value) => (value + 459.67M) * 5 / 9;
}
private class RankineToKelvinMapper : IKelvinMapper
{
public decimal ToKelvins(decimal value) => value * 5 / 9;
}
private class KelvinToKelvinMapper : IKelvinMapper
{
public decimal ToKelvins(decimal value) => value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment