Click here to Skip to main content
15,900,461 members
Home / Discussions / Design and Architecture
   

Design and Architecture

 
AnswerRe: What tools do you use to design? PinPopular
R. Giskard Reventlov16-Aug-10 0:22
R. Giskard Reventlov16-Aug-10 0:22 
GeneralRe: What tools do you use to design? Pin
bleedingfingers24-Aug-10 2:00
bleedingfingers24-Aug-10 2:00 
GeneralRe: What tools do you use to design? Pin
mohit`127-Sep-10 10:15
mohit`127-Sep-10 10:15 
AnswerRe: What tools do you use to design? Pin
Megidolaon12-Oct-10 5:18
Megidolaon12-Oct-10 5:18 
GeneralRe: What tools do you use to design? Pin
bleedingfingers12-Oct-10 21:16
bleedingfingers12-Oct-10 21:16 
QuestionWhat kind of Methodology more suitable? Pin
Nasri879-Aug-10 2:55
Nasri879-Aug-10 2:55 
AnswerRe: What kind of Methodology more suitable? Pin
Richard MacCutchan9-Aug-10 22:26
mveRichard MacCutchan9-Aug-10 22:26 
QuestionImplementation MVC of problem Pin
fell02068-Aug-10 15:55
fell02068-Aug-10 15:55 
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.*;

public class View implements Viewable {

	private int no1;
	private int no2;
	private Controller c;
	private String name;

	public View(String n) {
		// TODO Auto-generated constructor stub
		this.name = n;
	}

	public String getName() {
		return this.name;
	}

	public void addController(Controller c) {
		this.c = c;
	}

	public void display() {
		Scanner s = new Scanner(System.in);
		System.out.print("No 1:");
		no1 = s.nextInt();
		System.out.print("No 2:");
		no2 = s.nextInt();
		c.sumNumber(this, no1, no2);
	}

	public void show(int result) {
		System.out.println(no1 + "+" + no2 + "=" + result);
	}
}


import java.util.Scanner;

public class View2 implements Viewable {
	private int no1;
	private int no2;
	private Controller c;
	private String name;

	public View2(String n) {
		this.name = n;
	}

	public String getName() {
		return this.name;
	}

	public void addController(Controller c) {
		this.c = c;
	}

	public void show(int result) {
		System.out.println(no1 + "-" + no2 + "=" + result);
	}

	public void display() {
		Scanner s = new Scanner(System.in);
		System.out.print("No 1:");
		no1 = s.nextInt();
		System.out.print("No 2:");
		no2 = s.nextInt();
		c.substractNumber(this, no1, no2);
	}

}

AnswerRe: Implementation MVC of problem Pin
R. Giskard Reventlov9-Aug-10 3:03
R. Giskard Reventlov9-Aug-10 3:03 
QuestionBank Transfer Pin
Gjm6-Aug-10 3:34
Gjm6-Aug-10 3:34 
QuestionDynamically filling dropdown values or manually Pin
anjelone24-Aug-10 16:03
anjelone24-Aug-10 16:03 
AnswerRe: Dynamically filling dropdown values or manually Pin
Pete O'Hanlon4-Aug-10 22:11
mvePete O'Hanlon4-Aug-10 22:11 
GeneralRe: Dynamically filling dropdown values or manually Pin
anjelone25-Aug-10 9:07
anjelone25-Aug-10 9:07 
GeneralRe: Dynamically filling dropdown values or manually Pin
Pete O'Hanlon5-Aug-10 12:07
mvePete O'Hanlon5-Aug-10 12:07 
GeneralRe: Dynamically filling dropdown values or manually Pin
Eddy Vluggen6-Aug-10 4:29
professionalEddy Vluggen6-Aug-10 4:29 
GeneralRe: Dynamically filling dropdown values or manually Pin
Keith Barrow25-Sep-10 0:20
professionalKeith Barrow25-Sep-10 0:20 
GeneralRe: Dynamically filling dropdown values or manually Pin
PIEBALDconsult24-Sep-10 21:57
mvePIEBALDconsult24-Sep-10 21:57 
QuestionEnterprise Applications Pin
Ali el2-Aug-10 1:34
Ali el2-Aug-10 1:34 
AnswerRe: Enterprise Applications Pin
Pete O'Hanlon2-Aug-10 2:11
mvePete O'Hanlon2-Aug-10 2:11 
Questionhow to comprehend the definition of Bridge pattern by Gof? Pin
zxjun8422-Jul-10 18:56
zxjun8422-Jul-10 18:56 
QuestionSimple UML Question Pin
Nadunwow29-Jun-10 8:18
Nadunwow29-Jun-10 8:18 
AnswerRe: Simple UML Question Pin
Richard MacCutchan29-Jun-10 9:17
mveRichard MacCutchan29-Jun-10 9:17 
GeneralRe: Simple UML Question Pin
Nadunwow2-Jul-10 7:11
Nadunwow2-Jul-10 7:11 
AnswerRe: Simple UML Question Pin
Sameerkumar Namdeo16-Aug-10 0:10
Sameerkumar Namdeo16-Aug-10 0:10 
QuestionBuilding troubleshooting application Pin
sumit703428-Jun-10 20:53
sumit703428-Jun-10 20:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.