Exercise Foundation: Sensor Hierarchy#

Hypothetical#

We are an organization that sits on a large pile of software. Sensors, temperature sensors actually, are fundamental in that pile, and there are many sensor implementations around. All are organized in a class hierarchy, starting at an abstract base class (an interface):

#pragma once

class Sensor
{
public:
    virtual ~Sensor() = default;

    // returns degrees Celsius
    virtual double get_temperature() = 0;
};

Two concrete implementations of such sensors that we will use in the exercise series in this course are:

  • RandomSensor. That sensor yields floating point random numbers in a configurable range.

  • ConstantSensor. That one always yields the same temperature. Cool for testing.

We will extend that hierarchy along with the exercises.

Class Hierarchy#

@startuml

interface Sensor {
  + double get_temperature()
}

class I2CSensor {
  + double get_value()
}
class RandomSensor {
  + double get_value()
}
class ConstantSensor {
  + double get_value()
}

Sensor <|.. I2CSensor
Sensor <|.. RandomSensor
Sensor <|.. ConstantSensor

@enduml