BAEL-4994 code added for mvc and mvp architecture
This commit is contained in:
parent
19129f3721
commit
48993c9718
|
@ -0,0 +1,24 @@
|
|||
package com.baeldung.mvc;
|
||||
|
||||
public class MvcMainClass {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Product model = retrieveProductFromDatabase();
|
||||
ProductView view = new ProductView();
|
||||
model.setProductView(view);
|
||||
model.showProduct();
|
||||
|
||||
ProductController controller = new ProductController(model);
|
||||
controller.setProductName("SmartPhone");
|
||||
model.showProduct();
|
||||
}
|
||||
|
||||
private static Product retrieveProductFromDatabase() {
|
||||
Product product = new Product();
|
||||
product.setProductName("Mobile");
|
||||
product.setProductDescription("New Brand");
|
||||
product.setProductPrice(1000.0);
|
||||
return product;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package com.baeldung.mvc;
|
||||
|
||||
public class Product {
|
||||
private String productName;
|
||||
private String productDescription;
|
||||
private Double productPrice;
|
||||
private ProductView productView;
|
||||
|
||||
public String getProductName() {
|
||||
return productName;
|
||||
}
|
||||
|
||||
public void setProductName(String productName) {
|
||||
this.productName = productName;
|
||||
}
|
||||
|
||||
public String getProductDescription() {
|
||||
return productDescription;
|
||||
}
|
||||
|
||||
public void setProductDescription(String productDescription) {
|
||||
this.productDescription = productDescription;
|
||||
}
|
||||
|
||||
public Double getProductPrice() {
|
||||
return productPrice;
|
||||
}
|
||||
|
||||
public void setProductPrice(Double productPrice) {
|
||||
this.productPrice = productPrice;
|
||||
}
|
||||
|
||||
public ProductView getProductView() {
|
||||
return productView;
|
||||
}
|
||||
|
||||
public void setProductView(ProductView productView) {
|
||||
this.productView = productView;
|
||||
}
|
||||
|
||||
public void showProduct() {
|
||||
productView.printProductDetails(productName, productDescription, productPrice);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
package com.baeldung.mvc;
|
||||
|
||||
public class ProductController {
|
||||
private final Product product;
|
||||
|
||||
public ProductController(Product product) {
|
||||
this.product = product;
|
||||
}
|
||||
|
||||
public String getProductName() {
|
||||
return product.getProductName();
|
||||
}
|
||||
|
||||
public void setProductName(String productName) {
|
||||
product.setProductName(productName);
|
||||
}
|
||||
|
||||
public String getProductDescription() {
|
||||
return product.getProductDescription();
|
||||
}
|
||||
|
||||
public void setProductDescription(String productDescription) {
|
||||
product.setProductDescription(productDescription);
|
||||
}
|
||||
|
||||
public Double getProductPrice() {
|
||||
return product.getProductPrice();
|
||||
}
|
||||
|
||||
public void setProductPrice(Double productPrice) {
|
||||
product.setProductPrice(productPrice);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package com.baeldung.mvc;
|
||||
|
||||
public class ProductView {
|
||||
public void printProductDetails(String productName, String productDescription, Double productPrice) {
|
||||
System.out.println("Product details:");
|
||||
System.out.println("product Name: " + productName);
|
||||
System.out.println("product Description: " + productDescription);
|
||||
System.out.println("product price: " + productPrice);
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.baeldung.mvp;
|
||||
|
||||
public class MvpMainClass {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
Product model = retrieveProductFromDatabase();
|
||||
ProductView view = new ProductView();
|
||||
ProductController controller = new ProductController(model, view);
|
||||
controller.showProduct();
|
||||
controller.setProductName("SmartPhone");
|
||||
controller.showProduct();
|
||||
}
|
||||
|
||||
private static Product retrieveProductFromDatabase() {
|
||||
Product product = new Product();
|
||||
product.setProductName("Mobile");
|
||||
product.setProductDescription("New Brand");
|
||||
product.setProductPrice(1000.0);
|
||||
return product;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
package com.baeldung.mvp;
|
||||
|
||||
public class Product {
|
||||
private String productName;
|
||||
private String productDescription;
|
||||
private Double productPrice;
|
||||
|
||||
public String getProductName() {
|
||||
return productName;
|
||||
}
|
||||
|
||||
public void setProductName(String productName) {
|
||||
this.productName = productName;
|
||||
}
|
||||
|
||||
public String getProductDescription() {
|
||||
return productDescription;
|
||||
}
|
||||
|
||||
public void setProductDescription(String productDescription) {
|
||||
this.productDescription = productDescription;
|
||||
}
|
||||
|
||||
public Double getProductPrice() {
|
||||
return productPrice;
|
||||
}
|
||||
|
||||
public void setProductPrice(Double productPrice) {
|
||||
this.productPrice = productPrice;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package com.baeldung.mvp;
|
||||
|
||||
public class ProductController {
|
||||
private final Product product;
|
||||
private final ProductView productView;
|
||||
|
||||
public ProductController(Product product, ProductView productView) {
|
||||
this.product = product;
|
||||
this.productView = productView;
|
||||
}
|
||||
|
||||
public String getProductName() {
|
||||
return product.getProductName();
|
||||
}
|
||||
|
||||
public void setProductName(String productName) {
|
||||
product.setProductName(productName);
|
||||
}
|
||||
|
||||
public String getProductDescription() {
|
||||
return product.getProductDescription();
|
||||
}
|
||||
|
||||
public void setProductDescription(String productDescription) {
|
||||
product.setProductDescription(productDescription);
|
||||
}
|
||||
|
||||
public Double getProductPrice() {
|
||||
return product.getProductPrice();
|
||||
}
|
||||
|
||||
public void setProductPrice(Double productPrice) {
|
||||
product.setProductPrice(productPrice);
|
||||
}
|
||||
|
||||
public void showProduct() {
|
||||
productView.printProductDetails(product.getProductName(), product.getProductDescription(), product.getProductPrice());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package com.baeldung.mvp;
|
||||
|
||||
public class ProductView {
|
||||
public void printProductDetails(String productName, String productDescription, Double productPrice) {
|
||||
System.out.println("Product details:");
|
||||
System.out.println("product Name: " + productName);
|
||||
System.out.println("product Description: " + productDescription);
|
||||
System.out.println("product price: " + productPrice);
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue