Skip to content

Implement View Helper pattern #3278

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open

Conversation

e5LA
Copy link
Contributor

@e5LA e5LA commented May 13, 2025

What does this PR do?

This PR implements the View Helper design pattern to improve the separation of concerns within the application. It introduces a View Helper class responsible for handling data formatting and processing tasks. The Controller is updated to delegate relevant responsibilities to the View Helper, and the View is refactored to consume the prepared data, resulting in cleaner, more maintainable code.

Fixes #1263

Copy link

github-actions bot commented May 13, 2025

PR Summary

This PR implements the View Helper design pattern to improve the separation of concerns. It introduces a ViewHelper class responsible for handling data formatting and processing tasks. The Controller is updated to delegate responsibilities to the ViewHelper, and the View is refactored to consume the prepared data, resulting in cleaner, more maintainable code. A new module view-helper was created, including interfaces for View and ViewHelper, implementations for Product, ProductViewModel, ProductViewHelper, ConsoleProductView, ProductController, and tests.

Changes

File Summary
pom.xml The view-helper module was added to the project's modules list. The order of modules was adjusted to maintain alphabetical order.
view-helper/README.md A comprehensive README file was added, detailing the View Helper pattern, its implementation, use cases, benefits, and related patterns. Includes diagrams.
view-helper/etc/view-helper-sequence-diagram.png New file.
view-helper/etc/view-helper-sequence-diagram.puml New file.
view-helper/etc/view-helper.png New file.
view-helper/etc/view-helper.puml New file.
view-helper/pom.xml A pom.xml file was added for the view-helper module, defining its dependencies (slf4j-api, logback-classic, junit-jupiter-engine).
view-helper/src/main/java/com/iluwatar/viewhelper/App.java This class demonstrates the View Helper pattern by creating a Product, using ProductViewHelper to format it, and rendering it with ConsoleProductView.
view-helper/src/main/java/com/iluwatar/viewhelper/ConsoleProductView.java Implements the View interface, rendering a ProductViewModel to the console using a logger.
view-helper/src/main/java/com/iluwatar/viewhelper/Product.java A simple record defining a Product with its attributes: name, price, release date, and a boolean indicating whether it's discounted.
view-helper/src/main/java/com/iluwatar/viewhelper/ProductController.java The controller takes a Product, uses a ViewHelper to prepare a ProductViewModel, and then uses a View to render it.
view-helper/src/main/java/com/iluwatar/viewhelper/ProductViewHelper.java Implements the ViewHelper interface, formatting a Product into a ProductViewModel for display. Handles currency formatting and date formatting.
view-helper/src/main/java/com/iluwatar/viewhelper/ProductViewModel.java A record representing the view model for a Product, containing formatted data for display.
view-helper/src/main/java/com/iluwatar/viewhelper/View.java Interface defining a View that can render data of type V.
view-helper/src/main/java/com/iluwatar/viewhelper/ViewHelper.java Interface defining a ViewHelper that prepares data of type M for display as type V.
view-helper/src/test/java/com/iluwatar/viewhelper/AppTest.java Tests that the main application runs without throwing exceptions.
view-helper/src/test/java/com/iluwatar/viewhelper/ProductViewHelperTest.java Unit tests for the ProductViewHelper, verifying the formatting of products with and without discounts.

autogenerated by presubmit.ai

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Review Summary

Commits Considered (11)
  • 3e1263e: Merge remote-tracking branch 'upstream/master' into 1263-view-helper

Conflicts:

pom.xml

Files Processed (17)
  • pom.xml (2 hunks)
  • view-helper/README.md (1 hunk)
  • view-helper/etc/view-helper-sequence-diagram.png (0 hunks)
  • view-helper/etc/view-helper-sequence-diagram.puml (1 hunk)
  • view-helper/etc/view-helper.png (0 hunks)
  • view-helper/etc/view-helper.puml (1 hunk)
  • view-helper/pom.xml (1 hunk)
  • view-helper/src/main/java/com/iluwatar/viewhelper/App.java (1 hunk)
  • view-helper/src/main/java/com/iluwatar/viewhelper/ConsoleProductView.java (1 hunk)
  • view-helper/src/main/java/com/iluwatar/viewhelper/Product.java (1 hunk)
  • view-helper/src/main/java/com/iluwatar/viewhelper/ProductController.java (1 hunk)
  • view-helper/src/main/java/com/iluwatar/viewhelper/ProductViewHelper.java (1 hunk)
  • view-helper/src/main/java/com/iluwatar/viewhelper/ProductViewModel.java (1 hunk)
  • view-helper/src/main/java/com/iluwatar/viewhelper/View.java (1 hunk)
  • view-helper/src/main/java/com/iluwatar/viewhelper/ViewHelper.java (1 hunk)
  • view-helper/src/test/java/com/iluwatar/viewhelper/AppTest.java (1 hunk)
  • view-helper/src/test/java/com/iluwatar/viewhelper/ProductViewHelperTest.java (1 hunk)
Actionable Comments (0)
Skipped Comments (0)

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Review Summary

Commits Considered (1)
Files Processed (16)
  • pom.xml (2 hunks)
  • view-helper/README.md (1 hunk)
  • view-helper/etc/view-helper-sequence-diagram.png (0 hunks)
  • view-helper/etc/view-helper-sequence-diagram.puml (1 hunk)
  • view-helper/etc/view-helper.png (0 hunks)
  • view-helper/etc/view-helper.puml (1 hunk)
  • view-helper/src/main/java/com/iluwatar/viewhelper/App.java (1 hunk)
  • view-helper/src/main/java/com/iluwatar/viewhelper/ConsoleProductView.java (1 hunk)
  • view-helper/src/main/java/com/iluwatar/viewhelper/Product.java (1 hunk)
  • view-helper/src/main/java/com/iluwatar/viewhelper/ProductController.java (1 hunk)
  • view-helper/src/main/java/com/iluwatar/viewhelper/ProductViewHelper.java (1 hunk)
  • view-helper/src/main/java/com/iluwatar/viewhelper/ProductViewModel.java (1 hunk)
  • view-helper/src/main/java/com/iluwatar/viewhelper/View.java (1 hunk)
  • view-helper/src/main/java/com/iluwatar/viewhelper/ViewHelper.java (1 hunk)
  • view-helper/src/test/java/com/iluwatar/viewhelper/AppTest.java (1 hunk)
  • view-helper/src/test/java/com/iluwatar/viewhelper/ProductViewHelperTest.java (1 hunk)
Actionable Comments (0)
Skipped Comments (0)

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
7 Security Hotspots
E Reliability Rating on New Code (required ≥ A)
E Security Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

View Helper pattern
1 participant