iluwatar / iluwatar/java-design-patterns

State-Action-Model pattern

Open
#511 13 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

epic: pattern info: help wanted type: feature
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:

  1. 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.
  2. 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.
  3. 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:

  1. SAM.js Official Documentation
  2. InfoQ Article on SAM Pattern
  3. Project Contribution Guidelines

Acceptance Criteria:

  1. Implement a basic example of the SAM pattern in the project, demonstrating the separation of state, actions, and model.
  2. Ensure that the implementation is well-documented, with clear comments and explanations for each component of the pattern.
  3. Provide unit tests for the state transitions and actions to validate the correctness of the implementation.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.