iluwatar / java-design-patterns

Design patterns implemented in Java
https://java-design-patterns.com
Other
88.46k stars 26.23k forks source link

State-Action-Model pattern #511

Open iluwatar opened 7 years ago

iluwatar commented 7 years ago

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.
iluwatar commented 7 years ago

https://www.infoq.com/articles/sam-lessons-learned-front-end-reactive-architectures

vladislavsimic commented 7 years ago

Hi @iluwatar . I am working on this.

iluwatar commented 7 years ago

Ok @dovlasim

npathai commented 6 years ago

https://www.linkedin.com/pulse/introducing-sam-pattern-alternative-mvc-jean-jacques-dubray

iluwatar commented 6 years ago

@vladislavsimic are you still implementing this?

iluwatar commented 4 years ago

The task is free to take

PalAditya commented 4 years ago

Hi, I would like to pick up this pattern next. Seems pretty interesting, and I am thinking of implementing it as a two-player game simulation. Should I go ahead? 😄

iluwatar commented 4 years ago

@PalAditya sounds interesting, please go ahead :blush:

PalAditya commented 4 years ago

Hi, @iluwatar , I have had something come up in real life and I don't think I would be able to help out with this right now. I guess it would be better if you could unassign me and set the task as free again so that someone else could take it up, and I could carry on with this if nobody else has taken it up yet by the time I'm back.

Really sorry about this 😅

iluwatar commented 4 years ago

No problem @PalAditya, welcome back any time!

iluwatar commented 4 years ago

This issue is free for taking again.