I would like to ask about possible improvement of this code. I have created very simple code using MVC pattern. Is there any logic or anything to change? I tried to keep MVC idea.
This is model, class Customer
:
package customereditor;
public class Customer {
private int ID;
private String name;
private String surname;
public int getID() {
return ID;
}
public void setID(int ID) {
this.ID = ID;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
}
This is view, class CustomerView
:
package customereditor;
public class CustomerView {
public void displayCustomer(int customerID, String customerName, String customerSurname) {
System.out.println("ID: " + customerID);
System.out.println("Name: " + customerName);
System.out.println("Surname: " + customerSurname);
}
}
This is controller, class CustomerController
:
package customereditor;
public class CustomerController {
Customer model;
CustomerView view;
public CustomerController(Customer model, CustomerView view) {
this.model = model;
this.view = view;
}
public void setCustomerID(int customerID) {
model.setID(customerID);
}
public int getCustomerID() {
return model.getID();
}
public void setCustomerName(String customerName) {
model.setName(customerName);
}
public String getCustomerName() {
return model.getName();
}
public void setCustomerSurname(String customerSurname) {
model.setSurname(customerSurname);
}
public String getCustomerSurname() {
return model.getSurname();
}
public void displayCustomer() {
view.displayCustomer(model.getID(),model.getName(),model.getSurname());
}
}
And this is class with main method, class MainCustomer
:
package customereditor;
public class MainCustomer {
public static void main(String[] args) {
Customer model = new Customer();
CustomerView view = new CustomerView();
CustomerController controller = new CustomerController(model, view);
controller.setCustomerID(1);
controller.setCustomerName("John");
controller.setCustomerSurname("Doe");
controller.displayCustomer();
}
}