iluwatar / iluwatar/java-design-patterns
State-Action-Model pattern
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 94.7k
- Forks
- 27.4k
- Avg merge
- 3d 4h
- Merged PRs (30d)
- 10
Description
Description:
The State-Action-Model (SAM) pattern is a modern approach to state management in JavaScript applications. Unlike traditional MVC frameworks, SAM separates the state, actions, and model, providing a clear and manageable structure for application logic. This pattern enhances testability and maintainability by isolating state transitions and business logic from the view.
Main Elements of the SAM Pattern:
- State: Represents the application's state and is managed separately from the business logic and UI. The state is immutable, meaning any change results in a new state rather than modifying the existing state.
- Actions: Encapsulate the business logic and are responsible for transitioning the state. Actions receive the current state and an event, process them, and return the new state.
- Model: The model serves as an intermediary that controls the interaction between the state and actions. It ensures that actions are executed correctly and that state transitions are valid.
References:
Acceptance Criteria:
- Implement a basic example of the SAM pattern in the project, demonstrating the separation of state, actions, and model.
- Ensure that the implementation is well-documented, with clear comments and explanations for each component of the pattern.
- Provide unit tests for the state transitions and actions to validate the correctness of the implementation.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No files, tests, or entry points are named. Start by reviewing the repository's existing design-pattern layout and contribution guidelines, then compare the SAM.js references with the project's Java conventions. Done means a basic State, Action, and Model example, explanatory documentation, and unit tests covering state transitions and actions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, javascript
- Domain
- design, testing-qa
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100