Created
February 15, 2018 05:52
-
-
Save devforfu/eeab965f571517b2645a839768a2469a to your computer and use it in GitHub Desktop.
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
class _CelsiusConverter(TemperatureConverter): | |
""" | |
Concrete implementation of temperature converted which converts from Kelvin | |
into Celsius degrees. | |
""" | |
symbol = '°C' | |
def _convert(self, value): | |
return value - 273.15 | |
class _FahrenheitConverter: | |
""" | |
Concrete implementation of temperature converter which converts from Kelvin | |
into Fahrenheit degrees. | |
Note that this class does not directly inherit base class, but is | |
registered as derived class using ABCMeta.register method. Though in this | |
case, there is no a default implementation of `format` method and `name` | |
property. | |
""" | |
symbol = '°F' | |
def _convert(self, value): | |
return value * 9./5 - 459.67 | |
def format(self, value): | |
return '%.2f (%s)' % (self._convert(value), self.symbol) | |
@property | |
def name(self): | |
return 'FahrenheitConverter' | |
TemperatureConverter.register(_FahrenheitConverter) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment