I am writing a program that manages a user's budgets. I have to use the MVC pattern. I had a doubt about how things should be done. To build an account from the command line, the user will have to enter the username, description and other parameters.
i've got: View (View), Performer(Controller) and Ledger (Model);
This is my method in class View
public void createAccount(Performer<T> performer) {
String name = name();
if(performer.existAccount(name)) {
System.err.println("This account already exist");
createAccount(performer);
}
int id = idAccount();
AccountType type = accountType();
String description = description();
Double value = value();
boolean add = performer.addNewAccount(type, id, name, description, value);
printMessage(add);
}
The methods name(), description(), idAccount() requires inserting a string.
I used a switch to select the method to run. Then when a user wants to create a new account, type ADD and start the createAccount() method.
In mine Controller, I used this method which calls ledger.addTag () which adds it to the list of accounts on the model
public boolean addNewAccount(AccountType type, int id, String name, String description, double opening) {
return ledger.addAccount(type, id, name, description, opening);
}
In mine MODEL,
public boolean addAccount(AccountType type, int id, String name, String description, double opening){
Account bill = new Bill(type, id, name, description, opening);
if(!getAccount().contains(bill)) {
account.add(bill);
return true;
}
return false;
}
My question is: input such as name (), description () ... should they be called in the view or should they be done in the controller?
Does my program violate the definition of MVC?
Aucun commentaire:
Enregistrer un commentaire