diff --git a/mvc-mvp/src/com/baeldung/mvc/MvcMainClass.java b/mvc-mvp/src/com/baeldung/mvc/MvcMainClass.java new file mode 100644 index 0000000000..479c8dd591 --- /dev/null +++ b/mvc-mvp/src/com/baeldung/mvc/MvcMainClass.java @@ -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; + } +} diff --git a/mvc-mvp/src/com/baeldung/mvc/Product.java b/mvc-mvp/src/com/baeldung/mvc/Product.java new file mode 100644 index 0000000000..2e05e26a3a --- /dev/null +++ b/mvc-mvp/src/com/baeldung/mvc/Product.java @@ -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); + } + +} diff --git a/mvc-mvp/src/com/baeldung/mvc/ProductController.java b/mvc-mvp/src/com/baeldung/mvc/ProductController.java new file mode 100644 index 0000000000..673b179e57 --- /dev/null +++ b/mvc-mvp/src/com/baeldung/mvc/ProductController.java @@ -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); + } + +} diff --git a/mvc-mvp/src/com/baeldung/mvc/ProductView.java b/mvc-mvp/src/com/baeldung/mvc/ProductView.java new file mode 100644 index 0000000000..9e1b2e5cb7 --- /dev/null +++ b/mvc-mvp/src/com/baeldung/mvc/ProductView.java @@ -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); + + } +} diff --git a/mvc-mvp/src/com/baeldung/mvp/MvpMainClass.java b/mvc-mvp/src/com/baeldung/mvp/MvpMainClass.java new file mode 100644 index 0000000000..f40cccca74 --- /dev/null +++ b/mvc-mvp/src/com/baeldung/mvp/MvpMainClass.java @@ -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; + } +} diff --git a/mvc-mvp/src/com/baeldung/mvp/Product.java b/mvc-mvp/src/com/baeldung/mvp/Product.java new file mode 100644 index 0000000000..902aa7100c --- /dev/null +++ b/mvc-mvp/src/com/baeldung/mvp/Product.java @@ -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; + } + +} diff --git a/mvc-mvp/src/com/baeldung/mvp/ProductController.java b/mvc-mvp/src/com/baeldung/mvp/ProductController.java new file mode 100644 index 0000000000..5cf32b3f0b --- /dev/null +++ b/mvc-mvp/src/com/baeldung/mvp/ProductController.java @@ -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()); + } + +} diff --git a/mvc-mvp/src/com/baeldung/mvp/ProductView.java b/mvc-mvp/src/com/baeldung/mvp/ProductView.java new file mode 100644 index 0000000000..edb3dddddc --- /dev/null +++ b/mvc-mvp/src/com/baeldung/mvp/ProductView.java @@ -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); + + } +}