CMPUT 301

Software Engineering

Practice w23hm2q2


Model-View (UML)

Interpret the Java code below. It represents a pressure cooker, like the instant-pot. It’s a device that heats up food while under pressure. It provides an API to monitor the pressure and temperature of the pressure cooker. Currently class PressureCooker monitors pressure and temperature, draws a pressure gauge, graphs pressure over time, and draws a thermometer of the temperature. We want to add a temperature graph. Unfortunately we seem to be making this class too big.

Refactor/restructure this code AS A UML CLASS DIAGRAM OF RESTRUCTURED CODE to implement the Model-View pattern (variation of the MVC pattern, but without a dedicated Controller). Separate out models and views, and add new views as necessary to address the new features that were asked for. Explicitly improve cohesion with your restructuring of the code. You can make new classes and interfaces, you can move methods, rename methods, and make new methods.

On the diagram, CLEARLY LABEL which class(es) represents the Model and the View components. You do NOT need to have a Controller.

Draw a well-designed UML class diagram to represent this information. Provide the basic abstractions, attributes, methods, relationships, multiplicities, and navigabilities as appropriate. "..." means much code is omitted.

import java.util.*;
class PressureCooker {
    private double pressure;
    private double temperature;
    private LinkedList<Double> pastPressures;
    public double currentPressure() { return pressure; }
    /* called by the hardware driver */
    protected void setPressure(double p) {
        pastPressures.push(Double.valueOf(pressure));
        pressure = p;
                draw();
    }
    // drawPressureGauge draws a pressure gauge based on the
    // current value of pressure
    public void drawPressureGauge() {
        /* ... */
    }
    // drawPressureGraph draws a plot of pressure over time.
    public void drawPressureGraph() {
        /* ... */
    }
    // drawThermometer draws a thermometer representing the
    // temperature
    public void drawThermometer() {
        /* ... */
    }
    public void draw() {
        drawPressureGauge();
        drawPressureGraph();
        drawThermometer();
    }
}