Implementation MVC of problem
-
Everybody, I have some MVC of problem, I reference more information, and I write the Model, the Controller and more than one View, but I don't know my code is consistent with MVC? Please give some help! Thank you~
import java.util.*;
public class Initial {
/\*\* \* @param args \*/ public static void main(String\[\] args) { // TODO Auto-generated method stub View v = new View("View"); View2 v2 = new View2("View2"); Model m = new Model(); Controller c = new Controller(m); c.add(v); c.add(v2); v.display(); v2.display(); c.showAryList(); }
}
public class Model {
private enum States {
Add, Subtract
};private States state; public Model() { } public void changeToAdd() { this.state = States.Add; } public void changeToSubtract() { this.state = States.Subtract; } public int caculate(int x, int y) { int currentInt = 0; if (this.state == States.Add) { currentInt = add(x, y); } if (this.state == States.Subtract) { currentInt = substract(x, y); } return currentInt; } public int add(int x, int y) { return x + y; } public int substract(int x, int y) { return x - y; }
}
import java.util.*;
public class Controller {
// private Viewable v; private Model m; private List aryList; public Controller(Model m) { // TODO Auto-generated constructor stub this.m = m; aryList = new ArrayList(); } public void add(Viewable v) { aryList.add(v); System.out.println(v.getName() + "add!"); v.addController(this); } public void removeView(Viewable v) { aryList.remove(v); System.out.println(v.getName() + "remove!"); } public void sumNumber(Viewable v, int N1, int N2) { this.m.changeToAdd(); if (aryList.contains(v)) { ((Viewable) this.aryList.get(aryList.indexOf(v))).show(this.m .caculate(N1, N2)); } removeView(v); } public void substractNumber(Viewable v, int N1, int N2) { this.m.changeToSubtract(); if (aryList.contains(v)) { ((Viewable) this.aryList.get(aryList.indexOf(v))).show(this.m .substract(N1, N2)); } } public void showAryList() { for (int i = 0; i < aryList.size(); i++) { System.out.println(aryList.get(i).getClass()); } }
}
public interface Viewable {
// final String name;
public String getName();public void addController(Controller c); public void show(int result);
}
import java.util
-
Everybody, I have some MVC of problem, I reference more information, and I write the Model, the Controller and more than one View, but I don't know my code is consistent with MVC? Please give some help! Thank you~
import java.util.*;
public class Initial {
/\*\* \* @param args \*/ public static void main(String\[\] args) { // TODO Auto-generated method stub View v = new View("View"); View2 v2 = new View2("View2"); Model m = new Model(); Controller c = new Controller(m); c.add(v); c.add(v2); v.display(); v2.display(); c.showAryList(); }
}
public class Model {
private enum States {
Add, Subtract
};private States state; public Model() { } public void changeToAdd() { this.state = States.Add; } public void changeToSubtract() { this.state = States.Subtract; } public int caculate(int x, int y) { int currentInt = 0; if (this.state == States.Add) { currentInt = add(x, y); } if (this.state == States.Subtract) { currentInt = substract(x, y); } return currentInt; } public int add(int x, int y) { return x + y; } public int substract(int x, int y) { return x - y; }
}
import java.util.*;
public class Controller {
// private Viewable v; private Model m; private List aryList; public Controller(Model m) { // TODO Auto-generated constructor stub this.m = m; aryList = new ArrayList(); } public void add(Viewable v) { aryList.add(v); System.out.println(v.getName() + "add!"); v.addController(this); } public void removeView(Viewable v) { aryList.remove(v); System.out.println(v.getName() + "remove!"); } public void sumNumber(Viewable v, int N1, int N2) { this.m.changeToAdd(); if (aryList.contains(v)) { ((Viewable) this.aryList.get(aryList.indexOf(v))).show(this.m .caculate(N1, N2)); } removeView(v); } public void substractNumber(Viewable v, int N1, int N2) { this.m.changeToSubtract(); if (aryList.contains(v)) { ((Viewable) this.aryList.get(aryList.indexOf(v))).show(this.m .substract(N1, N2)); } } public void showAryList() { for (int i = 0; i < aryList.size(); i++) { System.out.println(aryList.get(i).getClass()); } }
}
public interface Viewable {
// final String name;
public String getName();public void addController(Controller c); public void show(int result);
}
import java.util
I doubt that anyone will want to wade through your code on the off-chance it might be problematic. The purpose of the forum is to answer questions relating to specific issues not for peer review.
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair. nils illegitimus carborundum me, me, me