Skip to main content
Ctrl+K
Jörg Faschingbauer - Home Jörg Faschingbauer - Home
  • Training Courses
  • About
  • Blog
  • Training Courses
  • About
  • Blog

Section Navigation

  • Course Descriptions
  • Pricing, Organizational
  • Log Of Past Courses
  • Complete Slide Material
    • Linux
    • Python Programming
    • The C Programming Language
    • C++ < 11
    • C++ >= 11
    • Design Patterns With C++
    • C++: TODO List
    • C++: Miscellaneous Live-Hacking
    • C++ Code
    • C++ Exercises
      • Working On Exercise Projects
      • OO Basics, Interfaces (Shapes)
      • C++ Exercises: Standard Template Library
      • Exercises: Design Patterns
        • Exercise: Singleton (Inflexible)
        • Exercise: Singleton (Flexible)
        • Exercise: Singleton (Flexible And Strict)
        • Exercise: Adapter
        • Exercise: Proxy (Rounding Thermometer)
        • Exercise: Proxy (Remote Thermometer)
        • Exercise: Decorator
        • Exercise: Composite
        • Exercise: Command
        • Exercise: Interpreter Combined With Adapter (And A Proxy)
        • Exercise: Arithmetic Expression Interpreter
        • Exercise: Adapter
        • Exercise: Abstract Factory
        • Solutions
      • FH Sensor OO (First Try)
      • Exercise: ConstantSensor_nopoly (Non-Polymorphic)
      • Exercise: RandomSensor_nopoly (Non-Polymorphic)
      • Exercise: MockSensor_nopoly (Non-Polymorphic)
      • Exercise: Mocking Switch (Non-Polymorphic)
      • Exercise: AveragingSensor_nopoly (Non-Polymorphic)
      • Exercise: Hysteresis_nopoly (Non-Polymorphic)
      • Exercise: LEDStripeDisplay_nopoly (Non-Polymorphic)
      • Exercise: Sensor Interface
      • Exercise: OneWire Sensor Class
      • Exercise: OneWire Sensor Factory
    • CMake
    • Is Software A Craft? Software Is A Craft! ⟶ Clean Code
    • Unit Testing With googletest
  • Training Courses
  • Complete Slide Material
  • C++ Exercises
  • Exercises: Design Patterns
  • Solutions
  • Solution: Proxy (Rounding Thermometer)

Solution: Proxy (Rounding Thermometer)#

  • Rounding Sensor (Proxy) Implementation

Rounding Sensor (Proxy) Implementation#

/trainings/material/soup/cxx-code/design-patterns-proxy/sensors/sensor-round.h#
#pragma once

#include "sensor.h"

#include <cmath>


class RoundingSensor : public Sensor
{
public:
    RoundingSensor(Sensor* sensor) : _sensor(sensor) {}

    virtual double get_temperature()
    {
        double value = _sensor->get_temperature();
        return std::round(value);
    }

private:
    Sensor* _sensor;
};
On this page
  • Rounding Sensor (Proxy) Implementation

© Copyright 2019-2025 (GPLv3), Jörg Faschingbauer.

Created using Sphinx 8.1.3.

Built with the PyData Sphinx Theme 0.16.1.

Show Source