Refactoring Weather Station to Observer Pattern

You are working for a firm that is entering the weather station market. As its first offering, the firm has created a prototype for a text-based application that creates and starts an independent Java Thread to periodically read a temperature sensor and print the retrieved value in Celsius. The station is represented by a WeatherStation object, while the sensor is an object in class KelvinTempSensor which, for the demonstration purposes, simply simulates the behavior of a sensor available from a local electronics supply house.

The simulated sensor has a reading() method which returns a 16-bit integer giving the temperature in Kelvin to the nearest 1/100th of a degree. More specifically, the value returned ranges from 0 through 65535 (the range of values that can be held in 16 bits), representing the temperatures 0.00°K (absolute zero) through 655.35°K. The WeatherStation object converts the Kelvin temperature to Celsius, using the fact that 0°C is 273.15°K, and prints the result as a string to the output window or terminal. The current temperature is reported once per second on a separate line as follows:

Reading is nnn.nn degrees C

where nnn.nn is the actual numeric temperature. See the source in WeatherStation.java for details.

In this activity we will  decouple the WeatherStation's actions of reading and printing temperature updates using the Observer pattern.The refactoring is accomplished by creating an Observable WeatherStation, and a new Observer TextUI class which prints out the temperature when the WeatherStation calls the update() method.

Starting Files

Download WS_Start.zip and extract the following files:
  1. WeatherStation.java
    The WeatherStation which currentl reads and prints updated temperature samples.

  2.  KelvinTempSensor.java
    The simulated temparature sensor object class - do not change this!.

  3. WeatherStationUML.pdf
    UML class and sequence diagrams for the structure and sequence of methods required to get and print a temperature sample.

  4. Text_WS.jar
    An exectuable jar file  to see the output generated by the WeatherStation.

  5. GofPatternCard.docx
    Complete this document as part of your submission.

Submission

Submit an WS_Refactored.zip file to the Observer Refactoring Dropbox containing the following files: