Skip to content

Weather

Andreas Krauss edited this page Jul 4, 2022 · 2 revisions

Please note that we shortened "Temperature" using "Temp", e.g., in parameter lists.

Micro Iteration 1 - Create TemperatureRecord

To model the TemperatureRecord, a simple class has been created.

Minimal Implementation

classDiagram
    class TemperatureRecord{
        -id: int
        -minTemperature: int
        -maxTemperature: int
        -lowerTemperatureLimit$: int
        -upperTemperatureLimit$: int
        +TemperatureRecord(id: int, minTemp: int, maxTemp: int)
        -validateTemperatureLimits(minTemp: int, maxTemp: int) boolean
        -validateTemperatureValues(minTemp: int, maxTemp: int) boolean
        +getId() int
        +getMinTemperature() int
        +getMaxTemperature() int
    }

Loading

Refactored Implementation In the refactoring, we added an interface to increase the extensibility. Furthermore, we added a factory to decouple the creation of the object from the later code.

classDiagram
    class TemperatureRecord{
        -id: int
        -minTemperature: int
        -maxTemperature: int
        -lowerTemperatureLimit: int
        -upperTemperatureLimit: int
        +TemperatureRecord(id: int, minTemp: int, maxTemp: int)
        -validateTemperatureLimits(minTemp: int, maxTemp: int) boolean
        -validateTemperatureValues(minTemp: int, maxTemp: int) boolean
        +getId() int
        +getMinTemperature() int
        +getMaxTemperature() int
    }

    class RecordFactory{
        +createRecord(id: String, minTemp: int, maxTemp: int)
    }

    class Record{
        <<interface>>
    }

    TemperatureRecord --> Record : implements
    RecordFactory --> TemperatureRecord : creates
    
Loading

Micro Iteration 2 - Add difference between Temperatures

We simply created the method to calculate the difference between the minimum and maximum temperature.

We refactored the solution by adding the getDifference() function to the interface Record.

classDiagram
    class TemperatureRecord{
        -id: int
        -minTemperature: int
        -maxTemperature: int
        -lowerTemperatureLimit: int
        -upperTemperatureLimit: int
        +TemperatureRecord(id: int, minTemp: int, maxTemp: int)
        -validateTemperatureLimits(minTemp: int, maxTemp: int) boolean
        -validateTemperatureValues(minTemp: int, maxTemp: int) boolean
        +getId() int
        +getMinTemperature() int
        +getMaxTemperature() int
        +getDifference() int
    }

    class RecordFactory{
        +createRecord(id: String, minTemp: int, maxTemp: int)
    }

    class Record{
        <<interface>>
        +getDifference(): int
    }

    TemperatureRecord --> Record : implements
    RecordFactory --> TemperatureRecord : creates
    
Loading

Micro Iteration 3 - Add CSV reader

We created a simple CSV Reader using internally a Buffered Reader. We further created an interface RecordReader to make the reader exchangable.

In this iteration, we exploited the structure of the CSV by using indexes for the selection of the attribute. Thus, the code was more readable for debugging. However, it already was planned to change this by determining the index of each required attribute in the CSV file and use that for selecting the respective attribute.

TLDR: Changes

  • add interface RecordReader
  • add class CSVRecordReader
classDiagram
    class TemperatureRecord{
        -id: int
        -minTemperature: int
        -maxTemperature: int
        -lowerTemperatureLimit: int
        -upperTemperatureLimit: int
        +TemperatureRecord(id: int, minTemp: int, maxTemp: int)
        -validateTemperatureLimits(minTemp: int, maxTemp: int) boolean
        -validateTemperatureValues(minTemp: int, maxTemp: int) boolean
        +getId() int
        +getMinTemperature() int
        +getMaxTemperature() int
        +getDifference() int
    }

    class RecordFactory{
        +createRecord(id: String, minTemp: int, maxTemp: int)
    }

    class Record{
        <<interface>>
        +getDifference(): int
    }

    class RecordReader{
        <<interface>>
        +readRecords(filepath: String, hasHeader:boolean): List<T>
    }

    class CSVRecordReader{
        +readRecords(filepath: String, hasHeader:boolean): List<T>
    }

    TemperatureRecord --> Record : implements
    RecordFactory --> TemperatureRecord : creates
    CSVRecordReader --> RecordReader : implements
    CSVRecordReader -- RecordFactory
    
Loading

Micro Iteration 4 - Add Feature to determine element with minimal difference

To determine the record with the lowest spread, we created a wrapper object that holds the records from the CSV file. Further, this structure allows us to create a function which is testable.

TLDR: Changes

  • add RecordCollection
classDiagram
    class TemperatureRecord{
        -id: int
        -minTemperature: int
        -maxTemperature: int
        -lowerTemperatureLimit: int
        -upperTemperatureLimit: int
        +TemperatureRecord(id: int, minTemp: int, maxTemp: int)
        -validateTemperatureLimits(minTemp: int, maxTemp: int) boolean
        -validateTemperatureValues(minTemp: int, maxTemp: int) boolean
        +getId() int
        +getMinTemperature() int
        +getMaxTemperature() int
        +getDifference() int
    }

    class RecordFactory{
        +createRecord(id: String, minTemp: int, maxTemp: int)
    }

    class Record{
        <<interface>>
        +getDifference(): int
    }

    class RecordReader{
        <<interface>>
        +readRecords(filepath: String, hasHeader:boolean): List<T>
    }

    class CSVRecordReader{
        +readRecords(filepath: String, hasHeader:boolean): List<T>
    }

    class RecordCollection{
        +RecordCollection(records: Record)
        +getRecordWithMinimalDifference(): String
    }

    TemperatureRecord --> Record : implements
    RecordFactory --> TemperatureRecord : creates
    CSVRecordReader --> RecordReader : implements
    CSVRecordReader -- RecordFactory
    
    RecordCollection "1" *-- "n" Record
Loading