BAEL-4994 moved to parrtern module

This commit is contained in:
Md Moinul Hossain 2021-06-25 00:17:10 +06:00
parent be2d8a668f
commit d478ffc079
8 changed files with 229 additions and 0 deletions

View File

@ -0,0 +1,24 @@
package com.baeldung.mvc_mvp.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;
}
}

View File

@ -0,0 +1,45 @@
package com.baeldung.mvc_mvp.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);
}
}

View File

@ -0,0 +1,34 @@
package com.baeldung.mvc_mvp.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);
}
}

View File

@ -0,0 +1,16 @@
package com.baeldung.mvc_mvp.mvc;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ProductView {
private static Logger log = LoggerFactory.getLogger(ProductView.class);
public void printProductDetails(String productName, String productDescription, Double productPrice) {
log.info("Product details:");
log.info("product Name: " + productName);
log.info("product Description: " + productDescription);
log.info("product price: " + productPrice);
}
}

View File

@ -0,0 +1,22 @@
package com.baeldung.mvc_mvp.mvp;
public class MvpMainClass {
public static void main(String[] args) {
Product model = retrieveProductFromDatabase();
ProductView view = new ProductView();
ProductPresenter presenter = new ProductPresenter(model, view);
presenter.showProduct();
presenter.setProductName("SmartPhone");
presenter.showProduct();
}
private static Product retrieveProductFromDatabase() {
Product product = new Product();
product.setProductName("Mobile");
product.setProductDescription("New Brand");
product.setProductPrice(1000.0);
return product;
}
}

View File

@ -0,0 +1,32 @@
package com.baeldung.mvc_mvp.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;
}
}

View File

@ -0,0 +1,40 @@
package com.baeldung.mvc_mvp.mvp;
public class ProductPresenter {
private final Product product;
private final ProductView productView;
public ProductPresenter(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());
}
}

View File

@ -0,0 +1,16 @@
package com.baeldung.mvc_mvp.mvp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ProductView {
private static Logger log = LoggerFactory.getLogger(ProductView.class);
public void printProductDetails(String productName, String productDescription, Double productPrice) {
log.info("Product details:");
log.info("product Name: " + productName);
log.info("product Description: " + productDescription);
log.info("product price: " + productPrice);
}
}