forked from eugenp/tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request eugenp#10915 from aang13/master
BAEL-4994 code added for mvc and mvp architecture
- Loading branch information
Showing
8 changed files
with
227 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
...ns/design-patterns-architectural/src/main/java/com/baeldung/mvc_mvp/mvc/MvcMainClass.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.setView(view); | ||
model.showProduct(); | ||
|
||
ProductController controller = new ProductController(model); | ||
controller.setName("SmartPhone"); | ||
model.showProduct(); | ||
} | ||
|
||
private static Product retrieveProductFromDatabase() { | ||
Product product = new Product(); | ||
product.setName("Mobile"); | ||
product.setDescription("New Brand"); | ||
product.setPrice(1000.0); | ||
return product; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
patterns/design-patterns-architectural/src/main/java/com/baeldung/mvc_mvp/mvc/Product.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.baeldung.mvc_mvp.mvc; | ||
|
||
public class Product { | ||
private String name; | ||
private String description; | ||
private Double price; | ||
private ProductView view; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
public void setDescription(String description) { | ||
this.description = description; | ||
} | ||
|
||
public Double getPrice() { | ||
return price; | ||
} | ||
|
||
public void setPrice(Double price) { | ||
this.price = price; | ||
} | ||
|
||
public ProductView getView() { | ||
return view; | ||
} | ||
|
||
public void setView(ProductView view) { | ||
this.view = view; | ||
} | ||
|
||
public void showProduct() { | ||
view.printProductDetails(name, description, price); | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
...sign-patterns-architectural/src/main/java/com/baeldung/mvc_mvp/mvc/ProductController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 getName() { | ||
return product.getName(); | ||
} | ||
|
||
public void setName(String name) { | ||
product.setName(name); | ||
} | ||
|
||
public String getDescription() { | ||
return product.getDescription(); | ||
} | ||
|
||
public void setDescription(String description) { | ||
product.setDescription(description); | ||
} | ||
|
||
public Double getPrice() { | ||
return product.getPrice(); | ||
} | ||
|
||
public void setPrice(Double price) { | ||
product.setPrice(price); | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
...rns/design-patterns-architectural/src/main/java/com/baeldung/mvc_mvp/mvc/ProductView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
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 name, String description, Double price) { | ||
log.info("Product details:"); | ||
log.info("product Name: " + name); | ||
log.info("product Description: " + description); | ||
log.info("product price: " + price); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...ns/design-patterns-architectural/src/main/java/com/baeldung/mvc_mvp/mvp/MvpMainClass.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.setName("SmartPhone"); | ||
presenter.showProduct(); | ||
} | ||
|
||
private static Product retrieveProductFromDatabase() { | ||
Product product = new Product(); | ||
product.setName("Mobile"); | ||
product.setDescription("New Brand"); | ||
product.setPrice(1000.0); | ||
return product; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
patterns/design-patterns-architectural/src/main/java/com/baeldung/mvc_mvp/mvp/Product.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.baeldung.mvc_mvp.mvp; | ||
|
||
public class Product { | ||
private String name; | ||
private String description; | ||
private Double price; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
public void setDescription(String description) { | ||
this.description = description; | ||
} | ||
|
||
public Double getPrice() { | ||
return price; | ||
} | ||
|
||
public void setPrice(Double price) { | ||
this.price = price; | ||
} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
...esign-patterns-architectural/src/main/java/com/baeldung/mvc_mvp/mvp/ProductPresenter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.baeldung.mvc_mvp.mvp; | ||
|
||
public class ProductPresenter { | ||
private final Product product; | ||
private final ProductView view; | ||
|
||
public ProductPresenter(Product product, ProductView view) { | ||
this.product = product; | ||
this.view = view; | ||
} | ||
|
||
public String getName() { | ||
return product.getName(); | ||
} | ||
|
||
public void setName(String name) { | ||
product.setName(name); | ||
} | ||
|
||
public String getDescription() { | ||
return product.getDescription(); | ||
} | ||
|
||
public void setDescription(String description) { | ||
product.setDescription(description); | ||
} | ||
|
||
public Double getProductPrice() { | ||
return product.getPrice(); | ||
} | ||
|
||
public void setPrice(Double price) { | ||
product.setPrice(price); | ||
} | ||
|
||
public void showProduct() { | ||
view.printProductDetails(product.getName(), product.getDescription(), product.getPrice()); | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
...rns/design-patterns-architectural/src/main/java/com/baeldung/mvc_mvp/mvp/ProductView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
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 name, String description, Double price) { | ||
log.info("Product details:"); | ||
log.info("product Name: " + name); | ||
log.info("product Description: " + description); | ||
log.info("product price: " + price); | ||
} | ||
} |