From d478ffc07916f100f56b0bf996cc6bbaa17ea95a Mon Sep 17 00:00:00 2001 From: Md Moinul Hossain Date: Fri, 25 Jun 2021 00:17:10 +0600 Subject: [PATCH] BAEL-4994 moved to parrtern module --- .../baeldung/mvc_mvp/mvc/MvcMainClass.java | 24 ++++++++++ .../com/baeldung/mvc_mvp/mvc/Product.java | 45 +++++++++++++++++++ .../mvc_mvp/mvc/ProductController.java | 34 ++++++++++++++ .../com/baeldung/mvc_mvp/mvc/ProductView.java | 16 +++++++ .../baeldung/mvc_mvp/mvp/MvpMainClass.java | 22 +++++++++ .../com/baeldung/mvc_mvp/mvp/Product.java | 32 +++++++++++++ .../mvc_mvp/mvp/ProductPresenter.java | 40 +++++++++++++++++ .../com/baeldung/mvc_mvp/mvp/ProductView.java | 16 +++++++ 8 files changed, 229 insertions(+) create mode 100644 patterns/design-patterns-architectural/src/main/java/com/baeldung/mvc_mvp/mvc/MvcMainClass.java create mode 100644 patterns/design-patterns-architectural/src/main/java/com/baeldung/mvc_mvp/mvc/Product.java create mode 100644 patterns/design-patterns-architectural/src/main/java/com/baeldung/mvc_mvp/mvc/ProductController.java create mode 100644 patterns/design-patterns-architectural/src/main/java/com/baeldung/mvc_mvp/mvc/ProductView.java create mode 100644 patterns/design-patterns-architectural/src/main/java/com/baeldung/mvc_mvp/mvp/MvpMainClass.java create mode 100644 patterns/design-patterns-architectural/src/main/java/com/baeldung/mvc_mvp/mvp/Product.java create mode 100644 patterns/design-patterns-architectural/src/main/java/com/baeldung/mvc_mvp/mvp/ProductPresenter.java create mode 100644 patterns/design-patterns-architectural/src/main/java/com/baeldung/mvc_mvp/mvp/ProductView.java diff --git a/patterns/design-patterns-architectural/src/main/java/com/baeldung/mvc_mvp/mvc/MvcMainClass.java b/patterns/design-patterns-architectural/src/main/java/com/baeldung/mvc_mvp/mvc/MvcMainClass.java new file mode 100644 index 0000000000..e89d7239eb --- /dev/null +++ b/patterns/design-patterns-architectural/src/main/java/com/baeldung/mvc_mvp/mvc/MvcMainClass.java @@ -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; + } +} diff --git a/patterns/design-patterns-architectural/src/main/java/com/baeldung/mvc_mvp/mvc/Product.java b/patterns/design-patterns-architectural/src/main/java/com/baeldung/mvc_mvp/mvc/Product.java new file mode 100644 index 0000000000..6e04b223e4 --- /dev/null +++ b/patterns/design-patterns-architectural/src/main/java/com/baeldung/mvc_mvp/mvc/Product.java @@ -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); + } + +} diff --git a/patterns/design-patterns-architectural/src/main/java/com/baeldung/mvc_mvp/mvc/ProductController.java b/patterns/design-patterns-architectural/src/main/java/com/baeldung/mvc_mvp/mvc/ProductController.java new file mode 100644 index 0000000000..922d4d703b --- /dev/null +++ b/patterns/design-patterns-architectural/src/main/java/com/baeldung/mvc_mvp/mvc/ProductController.java @@ -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); + } + +} diff --git a/patterns/design-patterns-architectural/src/main/java/com/baeldung/mvc_mvp/mvc/ProductView.java b/patterns/design-patterns-architectural/src/main/java/com/baeldung/mvc_mvp/mvc/ProductView.java new file mode 100644 index 0000000000..e8031b6398 --- /dev/null +++ b/patterns/design-patterns-architectural/src/main/java/com/baeldung/mvc_mvp/mvc/ProductView.java @@ -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); + + } +} diff --git a/patterns/design-patterns-architectural/src/main/java/com/baeldung/mvc_mvp/mvp/MvpMainClass.java b/patterns/design-patterns-architectural/src/main/java/com/baeldung/mvc_mvp/mvp/MvpMainClass.java new file mode 100644 index 0000000000..b501ac5ec5 --- /dev/null +++ b/patterns/design-patterns-architectural/src/main/java/com/baeldung/mvc_mvp/mvp/MvpMainClass.java @@ -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; + } +} diff --git a/patterns/design-patterns-architectural/src/main/java/com/baeldung/mvc_mvp/mvp/Product.java b/patterns/design-patterns-architectural/src/main/java/com/baeldung/mvc_mvp/mvp/Product.java new file mode 100644 index 0000000000..700ee15ef6 --- /dev/null +++ b/patterns/design-patterns-architectural/src/main/java/com/baeldung/mvc_mvp/mvp/Product.java @@ -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; + } + +} diff --git a/patterns/design-patterns-architectural/src/main/java/com/baeldung/mvc_mvp/mvp/ProductPresenter.java b/patterns/design-patterns-architectural/src/main/java/com/baeldung/mvc_mvp/mvp/ProductPresenter.java new file mode 100644 index 0000000000..984766b299 --- /dev/null +++ b/patterns/design-patterns-architectural/src/main/java/com/baeldung/mvc_mvp/mvp/ProductPresenter.java @@ -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()); + } + +} diff --git a/patterns/design-patterns-architectural/src/main/java/com/baeldung/mvc_mvp/mvp/ProductView.java b/patterns/design-patterns-architectural/src/main/java/com/baeldung/mvc_mvp/mvp/ProductView.java new file mode 100644 index 0000000000..7ee931612a --- /dev/null +++ b/patterns/design-patterns-architectural/src/main/java/com/baeldung/mvc_mvp/mvp/ProductView.java @@ -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); + + } +}