I have a this java application i am working on to get more experience with design patterns and OODesign. The application allows the user to select “equations” from a list. And then the user will be prompted with parameters for the selected equation and will be given a button to press to solve the equations.
I am implementing the equations as a strategy pattern. I am trying to figure out how to get the names of the equations into the list box. I was wondering if there was a way for the Equation classes that implement the EquationInterface to have a variable called equationName. That would allow the programmer to assign the specific equation a name when they are coding up the class for that specific equation. Code is listed below.
Example: When the programmer is designing a new equation to add to the program, they are required to include a name for the strategy created.
If you have any questions, please let me know. I am having a hard time explaining what i am trying to accomplish. And if you have any suggestions on a better design patter to use or way of accomplishing this goal, please let me know.
public class Equation {
public enum equationList {
DISTANCETRAVELLEDFALLINGOVERTIME,
TIMEFOROBJECTFALLDISTANCE
}
private EquationInterface solveInterface;
public Equation(EquationInterface solveInterface) {
this.solveInterface = solveInterface;
}
public void solve() {
solveInterface.performSolve();
}
public JPanel getParameterPanel() {
return solveInterface.createParameterPanel();
}
}
public interface EquationInterface {
public JPanel createParameterPanel();
public void performSolve();
}
public class DistanceTravelledFallingOverTime implements EquationInterface {
@Override
public void performSolve() {
// TODO Auto-generated method stub
System.out.println("DistanceTravelledFallingOverTime");
}
@Override
public JPanel createParameterPanel() {
// TODO Auto-generated method stub
return null;
}
}
I would use getter type method instead of a variable.
One sample implementation