OK, so I've done a bit of thinking and started coding. As you might know, when you start a maven project you get automatically a UI class, which I leave on the side for now, but I reckon that class will have the labels and all the GUI fields.
To start with, I created a ConverterModel class, which should contain the conversion logic.
So far it contains setters and getters, but I run into a problem:
package com.vaadin.project.converterRedone;
import com.vaadin.ui.CustomComponent;
public class ConverterModel extends CustomComponent {
private double unitToConvert;
private double multiplier;
public void setUnitToConvert(double unitToConvert){
this.unitToConvert = unitToConvert;
}
public void setMultiplier(double multiplier){
this.multiplier = multiplier;
}
private void doConversion(){
//TODO:do the conversion
}
}
So the problem is that to do the conversion I don't have to multiply all the time, but occasionally divide. So, say, to convert miles to km I multiply miles by 1.6, to convert km to miles I multiply km by 0.62 etc. If it was always a multiplication I could easily do it in the doConversion method, but to convert metres to yards I will have to divide metres by 0.9144: what I'm trying to say is that it's difficult to keep this doConversion a general method because I have to perform divisions and multiplications depending on what I want to convert to. So I will have to have a mechanism in place to decide whether it's going to be a multiplication or division. Does it make sense?