Problem statement
Design the object model and update APIs for a home weather-station hub that ingests readings from several sensors, keeps rolling aggregates, and pushes updates to multiple live displays.
Operating context. One hub gathers measurements from a handful of sensors (outdoor temperature, humidity, barometric pressure, wind, rainfall), each reporting at its own cadence. The hub maintains the latest value and rolling aggregates per measurement (for example, min/max/average over the last hour and last 24 hours). Several displays subscribe to the hub: a current-conditions panel, a statistics panel, and a simple forecast panel that infers a trend from pressure. When a new reading arrives, all interested displays must refresh. Users can toggle display units (metric or imperial). Everything runs in-process on the hub.
Out of scope. Sensor radio protocols and pairing, the cloud upload and public-weather-network endpoints, historical persistence to disk, the rendering/graphics layer of each display, and power management of battery sensors.
What to produce. The class hierarchy (hub, sensor / measurement source, reading, rolling-aggregate store, display subscribers, unit converter), the public API each class exposes, and how updates propagate. Be explicit about: how displays subscribe and receive updates via an Observer relationship so a new display type needs no hub change, how rolling aggregates update in O(1) amortised per reading, and how unit conversion is a pluggable concern applied at the display edge rather than mutating stored readings.
Must do 6
Functional requirements
- Ingest a reading from any sensor, updating the latest value and the rolling aggregates for that measurement.
- Let displays subscribe to and unsubscribe from the hub and receive a notification when relevant data changes.
- Maintain rolling min/max/average per measurement over configured windows (for example, last hour and last day).
- Serve current conditions, the rolling statistics, and a pressure-trend reading to whichever displays request them.