mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-10-14 00:16:48 +00:00
feat: Implement View Helper pattern (#3278)
* #1263 - creating new module for view-helper * #1263 - creating Product and ProductViewModel * #1263 - creating interfaces for View and ViewHelper * #1263 - creating ProductViewHelper and its test * #1263 - creating Console View for Product * #1263 - creating ProductController * #1263 - creating main App and its test * #1263 - adding license header * #1263 - keeping module in alphabetical order * #1263 - creating README and diagrams * #1263 apply spotless --------- Co-authored-by: Ilkka Seppälä <iluwatar@users.noreply.github.com>
This commit is contained in:
1 parent
dc3425dd0e
commit
a3fcc63167
17 files changed
+628
-2
No files matched your search
Binary file not shown.
|
After Width: | Height: | Size: 27 KiB |
@@ -0,0 +1,15 @@
|
||||
@startuml
|
||||
actor Client
|
||||
participant Controller
|
||||
participant ViewHelper
|
||||
participant View
|
||||
participant Product
|
||||
participant ProductViewModel
|
||||
|
||||
Client -> Controller : handle(product)
|
||||
Controller -> ViewHelper : prepare(product)
|
||||
ViewHelper -> Product : access data
|
||||
ViewHelper -> ProductViewModel : return formatted view model
|
||||
Controller -> View : render(viewModel)
|
||||
View -> Console : display output
|
||||
@enduml
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 55 KiB |
@@ -0,0 +1,45 @@
|
||||
@startuml
|
||||
package com.iluwatar.viewhelper {
|
||||
interface View<T> {
|
||||
+render(T model)
|
||||
}
|
||||
|
||||
interface ViewHelper<S, T> {
|
||||
+prepare(S source): T
|
||||
}
|
||||
|
||||
class Product {
|
||||
-name: String
|
||||
-price: BigDecimal
|
||||
-releaseDate: LocalDate
|
||||
-discounted: boolean
|
||||
}
|
||||
|
||||
class ProductViewModel {
|
||||
-name: String
|
||||
-price: String
|
||||
-releasedDate: String
|
||||
}
|
||||
|
||||
class ProductViewHelper {
|
||||
+prepare(Product): ProductViewModel
|
||||
}
|
||||
|
||||
class ConsoleProductView {
|
||||
+render(ProductViewModel)
|
||||
}
|
||||
|
||||
class ProductController {
|
||||
-helper: ViewHelper<Product, ProductViewModel>
|
||||
-view: View<ProductViewModel>
|
||||
+handle(Product)
|
||||
}
|
||||
}
|
||||
Product --> ProductViewHelper
|
||||
ProductViewHelper ..|> ViewHelper
|
||||
ConsoleProductView ..|> View
|
||||
ProductViewHelper --> ProductViewModel
|
||||
ProductController --> ProductViewHelper
|
||||
ProductController --> ConsoleProductView
|
||||
|
||||
@enduml
|
||||
Reference in new issue
Block a user