Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 30cb7b6

Browse files
SPSP
SP
authored and
SP
committedApr 19, 2025
iluwatar#1263 - creating ProductController
1 parent 3ada8d2 commit 30cb7b6

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
 
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.iluwatar.viewhelper;
2+
3+
/**
4+
* Controller delegates a {@link Product} to {@link ProductViewHelper} and then to {@link ConsoleProductView}.
5+
*/
6+
public class ProductController {
7+
8+
private final ViewHelper<Product, ProductViewModel> viewHelper;
9+
private final View<ProductViewModel> view;
10+
11+
public ProductController(ViewHelper<Product, ProductViewModel> viewHelper,
12+
View<ProductViewModel> view) {
13+
this.viewHelper = viewHelper;
14+
this.view = view;
15+
}
16+
17+
/** Passes the product to the helper for formatting and then forwards formatted product to the view. */
18+
public void handle(Product product) {
19+
view.render(viewHelper.prepare(product));
20+
}
21+
}

0 commit comments

Comments
 (0)
Please sign in to comment.