Skip to content
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

implemented the bloC design pattern issue #2374 #3128

Merged
merged 19 commits into from
Jan 16, 2025

Conversation

darkhyper24
Copy link
Contributor

What problem does this PR solve?

this PR implements the bloc design pattern which is a design pattern used to separate the UI components in dart and flutter from the states logic making the code more maintainable and testable by following these steps:

  1. the UI layer dispatches events like button clicks or user input to the bloc.
  2. the bloc processes the events and updates the state accordingly.
  3. the state is then emitted to listeners.
  4. the listeners concerned with the state then reacts to the state and update the interface accordingly.
    Close BLoC design pattern #2374

@darkhyper24
Copy link
Contributor Author

@iluwatar can you please review my pr?

bloC/Readme.md Outdated Show resolved Hide resolved
bloC/pom.xml Outdated Show resolved Hide resolved
bloC/pom.xml Outdated Show resolved Hide resolved
bloC/src/main/java/com/iluwatar/bloc/Main.java Outdated Show resolved Hide resolved
bloC/src/main/java/com/iluwatar/bloc/State.java Outdated Show resolved Hide resolved
pom.xml Outdated Show resolved Hide resolved
Copy link

github-actions bot commented Jan 14, 2025

PR Summary

This PR implements the Bloc design pattern in Java. It separates UI components from state logic, improving maintainability and testability. The Bloc manages the application's state and notifies listeners of changes, allowing for dynamic updates to the UI. The implementation includes a Bloc class, State class, StateListener interface, and supporting classes for listener management and UI interaction. Unit tests are included to verify functionality.

Changes

File Summary
bloc/README.md This file provides a comprehensive guide to the Bloc pattern in Java. It includes a detailed explanation, real-world examples, programmatic examples, and a discussion of benefits and trade-offs. It also covers related design patterns and references.
bloc/etc/bloc.png New file: Diagram of the Bloc pattern.
bloc/etc/bloc.puml New file: PlantUML diagram illustrating the Bloc pattern's class structure and relationships.
bloc/pom.xml New file: Maven project configuration file for the Bloc implementation. Specifies dependencies and build settings.
bloc/src/main/java/com/iluwatar/bloc/Bloc.java This class implements the core Bloc logic. It manages the current state, adds/removes listeners, and notifies listeners of state changes using the emitState method. It also includes methods to increment and decrement the state.
bloc/src/main/java/com/iluwatar/bloc/BlocUi.java This class creates and manages the UI components for the Bloc example. It sets up a simple GUI with buttons to interact with the Bloc and a label to display the current state.
bloc/src/main/java/com/iluwatar/bloc/ListenerManager.java This interface defines methods for managing listeners. It's implemented by the Bloc class to handle adding, removing, and retrieving listeners.
bloc/src/main/java/com/iluwatar/bloc/Main.java This class serves as the entry point for the application. It creates an instance of BlocUi to initialize and display the user interface.
bloc/src/main/java/com/iluwatar/bloc/State.java This class represents the application's state, holding an integer value. It uses a record declaration for conciseness.
bloc/src/main/java/com/iluwatar/bloc/StateListener.java This interface defines the contract for listeners that react to state changes. It has a single method, onStateChange, which is called when the state changes.
bloc/src/test/java/com/iluwatar/bloc/BlocTest.java This file contains JUnit tests for the Bloc class. Tests cover initial state, increment/decrement functionality, adding/removing listeners, and handling multiple listeners.
bloc/src/test/java/com/iluwatar/bloc/BlocUiTest.java This file contains JUnit tests for the BlocUi class. Tests cover increment, decrement, and toggle listener button functionality.
bloc/src/test/java/com/iluwatar/bloc/MainTest.java This file contains a JUnit test for the Main class, verifying that the createAndShowUi method of BlocUi is called.
pom.xml The bloc module was added to the project's modules list.

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 (15)

Bloc issue

separating ui from main file and adding more tests

  • 9d33b16: separating ui from main file and adding more tests
  • 60cd40e: Merge branch 'master' into master
  • 9ea484e: Merge remote-tracking branch 'origin/master'
  • 929eafb: fixed a test in MainTest file
  • 9ec0a0c: Merge branch 'master' into master
  • ee39a5c: added tests for the ui
  • 2c042a3: fixed checkstyle warnings
  • ede5f1d: added Readme file
  • 826a067: added bloC design pattern
  • 3a665b9: added bloC design pattern
Files Processed (14)
  • bloc/Readme.md (1 hunk)
  • bloc/etc/bloc.png (0 hunks)
  • bloc/etc/bloc.puml (1 hunk)
  • bloc/pom.xml (1 hunk)
  • bloc/src/main/java/com/iluwatar/bloc/Bloc.java (1 hunk)
  • bloc/src/main/java/com/iluwatar/bloc/BlocUi.java (1 hunk)
  • bloc/src/main/java/com/iluwatar/bloc/ListenerManager.java (1 hunk)
  • bloc/src/main/java/com/iluwatar/bloc/Main.java (1 hunk)
  • bloc/src/main/java/com/iluwatar/bloc/State.java (1 hunk)
  • bloc/src/main/java/com/iluwatar/bloc/StateListener.java (1 hunk)
  • bloc/src/test/java/com/iluwatar/bloc/BlocTest.java (1 hunk)
  • bloc/src/test/java/com/iluwatar/bloc/BlocUiTest.java (1 hunk)
  • bloc/src/test/java/com/iluwatar/bloc/MainTest.java (1 hunk)
  • pom.xml (1 hunk)
Actionable Comments (0)
Skipped Comments (0)

@darkhyper24 darkhyper24 reopened this Jan 14, 2025
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 (3)

fixed conflicts

  • 1330e91: syncing changes for conflicts
  • f1788c7: syncing changes for conflicts
Files Processed (14)
  • bloc/Readme.md (1 hunk)
  • bloc/etc/bloc.png (0 hunks)
  • bloc/etc/bloc.puml (1 hunk)
  • bloc/pom.xml (1 hunk)
  • bloc/src/main/java/com/iluwatar/bloc/Bloc.java (1 hunk)
  • bloc/src/main/java/com/iluwatar/bloc/BlocUi.java (1 hunk)
  • bloc/src/main/java/com/iluwatar/bloc/ListenerManager.java (1 hunk)
  • bloc/src/main/java/com/iluwatar/bloc/Main.java (1 hunk)
  • bloc/src/main/java/com/iluwatar/bloc/State.java (1 hunk)
  • bloc/src/main/java/com/iluwatar/bloc/StateListener.java (1 hunk)
  • bloc/src/test/java/com/iluwatar/bloc/BlocTest.java (1 hunk)
  • bloc/src/test/java/com/iluwatar/bloc/BlocUiTest.java (1 hunk)
  • bloc/src/test/java/com/iluwatar/bloc/MainTest.java (1 hunk)
  • pom.xml (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 (2)

Revert "fixed conflicts"

  • 2e1e34a: Revert "fixed conflicts"
Files Processed (0)
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 (14)
  • bloc/Readme.md (1 hunk)
  • bloc/etc/bloc.png (0 hunks)
  • bloc/etc/bloc.puml (1 hunk)
  • bloc/pom.xml (1 hunk)
  • bloc/src/main/java/com/iluwatar/bloc/Bloc.java (1 hunk)
  • bloc/src/main/java/com/iluwatar/bloc/BlocUi.java (1 hunk)
  • bloc/src/main/java/com/iluwatar/bloc/ListenerManager.java (1 hunk)
  • bloc/src/main/java/com/iluwatar/bloc/Main.java (1 hunk)
  • bloc/src/main/java/com/iluwatar/bloc/State.java (1 hunk)
  • bloc/src/main/java/com/iluwatar/bloc/StateListener.java (1 hunk)
  • bloc/src/test/java/com/iluwatar/bloc/BlocTest.java (1 hunk)
  • bloc/src/test/java/com/iluwatar/bloc/BlocUiTest.java (1 hunk)
  • bloc/src/test/java/com/iluwatar/bloc/MainTest.java (1 hunk)
  • pom.xml (1 hunk)
Actionable Comments (0)
Skipped Comments (0)

@darkhyper24 darkhyper24 requested a review from iluwatar January 14, 2025 19:49
@darkhyper24
Copy link
Contributor Author

sorry for the force pushing i had problems with outdated branches and had to recreate the module and delete the previous commits

bloc/Readme.md Outdated Show resolved Hide resolved
bloc/pom.xml Outdated Show resolved Hide resolved
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)
  • b5f2551: renamed readme file and abstracted pom file
Files Processed (2)
  • bloc/README.md (1 hunk)
  • bloc/pom.xml (1 hunk)
Actionable Comments (0)
Skipped Comments (1)
  • bloc/README.md [83-125]

    maintainability: "Improve Bloc class design by separating concerns."

@darkhyper24 darkhyper24 requested a review from iluwatar January 15, 2025 21:02
@iluwatar iluwatar merged commit 21115f4 into iluwatar:master Jan 16, 2025
2 checks passed
@iluwatar
Copy link
Owner

Looks good! Thank you for the contribution 🎉

@all-contributors please add @darkhyper24 for code

Copy link
Contributor

@iluwatar

I've put up a pull request to add @darkhyper24! 🎉

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

Successfully merging this pull request may close these issues.

BLoC design pattern
2 participants