Solution: Adapter¶
Adapter Class For Fahrenheit Sensors¶
#pragma once
#include <sensor-fahrenheit.h>
#include <sensor.h>
#include <memory>
class FahrenheitSensor_Adapter : public Sensor
{
public:
FahrenheitSensor_Adapter(FahrenheitSensor* adaptee);
double get_temperature();
private:
FahrenheitSensor* _adaptee;
};
#include "sensor-fahrenheit-adapter.h"
#include <sensor.h>
#include <memory>
FahrenheitSensor_Adapter::FahrenheitSensor_Adapter(FahrenheitSensor* adaptee)
: _adaptee(adaptee) {}
double FahrenheitSensor_Adapter::get_temperature()
{
double fahrenheit = _adaptee->get_temperature_f();
return (fahrenheit -32) * 5/9;
}