217 questions
1
vote
0
answers
114
views
How can I transform a monolithic state machine into a polymorphic state pattern when each state has unique extended methods and interfaces?
Please excuse me for how long this question is. I tried to shorten it as much as possible while still listing all of the various things I've tried and the problems I've run into.
I have a state ...
0
votes
0
answers
44
views
DDD: Modelling different type of aggregates with some common behaviour and state (Not of transitioning nature)
I am trying to implement an HR management module wherein I have three 3 types of employees namely RegularEmployee, ReengagedEmployee, OutsourcedEmployee. All of them have some common properties like ...
0
votes
1
answer
69
views
Abstracting a real hardware and simulated device with the same interface in Python
I am looking for a more idiomatic or concise OOP pattern to implement the equivalent of the following.
Interface and implementations
from abc import ABC, abstractmethod
from typing import override
...
1
vote
1
answer
1k
views
Managing Reactivity for Complex Nested Objects in Vue3
I'm working on a quite significantly sized web application that heavily interacts with Google Maps using Vue3 with composition API, typescript, and Pinia store.
The application is not complicated in ...
-1
votes
2
answers
275
views
Circular dependency was detected when I tried to implement state pattern
I am having this issue:
System.InvalidOperationException: 'A circular dependency was detected
for the service of type 'LibraryExamples.Water.States.IGasState'.
LibraryExamples.Water.IWater(...
1
vote
1
answer
149
views
Circular Dependencies in TypeScript with State Pattern
I am implementing the State design pattern in TypeScript and have run into circular dependency issues between Context, State, and state classes (StateA and StateB).
// context.ts
import { State } from ...
0
votes
1
answer
571
views
State pattern - determining the next state from multiple options
I am implementing a noise gate in Python, using the state design pattern.
My implementation takes an array of audio samples and, using the parameters of the noise gate, the audio sample magnitude ...
0
votes
2
answers
83
views
Role dependent behaviour in state pattern
I have a a class course which uses the state pattern to model the state of a course.
A course starts as a draft, can then be handed in to be approved by an admin. If the course was approved it can be ...
0
votes
1
answer
186
views
How to elegantly define shortest happy path between start and end state in a State Pattern design implementation?
When using state pattern, one is delegating behaviour of the Entity to the current State.
I have prepared SSCCE that I pasted below. We have an Entity which can transition between states : StartState, ...
1
vote
3
answers
1k
views
Rust typestate pattern: implement for multiple states?
I have a struct with several states:
struct Select;
struct Insert;
struct Delete;
// ...more states
struct Query<T> {
// ... some non-generic fields
marker: PhantomData<T>
}
I ...
3
votes
0
answers
78
views
How to keep the interface segregation principle while using the state design pattern?
In a previous question on StackOverflow, I asked about preventing the Context class within a State design pattern from having too many responsibilities, and I received an answer on that (moving it all ...
2
votes
1
answer
523
views
How to prevent a context class using the state design pattern from having too many responsibilities?
I am making use of the state design pattern for a project of mine where I have a Car class which is the context class and it can have 3 states - neutral, drive and park. In each of those states, the ...
0
votes
2
answers
660
views
For Enemy AI State Machine In Game Design, Should the State Itself Evaluate Logic to Transition to Next State?
I am building an Enemy AI State Machine, Where I have these scripts.
Setup
Enemy
EnemyStateManager
EnemyStateBase
States
InitialState
RoamingState
PursuingState
AttackingState
RetreatingState
When ...
1
vote
0
answers
320
views
How to use Shared Element Transition and State Pattern Together in Flutter?
I'm working on a Flutter widget that uses the state pattern whereby the layout changes in reaction to the state of an underlying model, so effectively there is a portion of the widget tree being ...
3
votes
1
answer
689
views
Alternatives to State Design Pattern
So I have been reading some design patterns on refactoring.guru, and have especially had an interest in behavioral design patterns.
However, there is one design pattern that made me question if it is ...
0
votes
0
answers
230
views
Combining the state and observable patterns in Rust
I've been interested in working with Rust for a while and wanted to recreate one of my school projects in it. This project involves creating an Order which goes through multiple stages much like this ...
3
votes
1
answer
1k
views
.NET - It is possible to use DI with the State Pattern?
I'm studying design patterns in .NET and currently i'm trying to implement the State Pattern. But today i got to a problem and i can't figure out how to fix this situation.
I have some state classes, ...
1
vote
2
answers
974
views
Best way to apply versioning to State object-oriented design pattern?
Main question
What are some good ways to manage state machine versions (including states themselves, state transition methods, etc) in object-oriented design, particularly during deployments when ...
0
votes
2
answers
249
views
C# State-Pattern private ChangeState
I´m trying to implement the State-Pattern using C# following this page. Here the UML of a State-Pattern.
The State it self sets the new sate in the context class. But here is my problem: I want to ...
3
votes
1
answer
676
views
How to apply the State Pattern with Dart enhanced enums
Dart 2.17 now has enhanced enums. Matt Carroll mentioned in his review that you could use the new enums to implement the State Pattern. I'm having trouble with this because I'm weak on both the State ...
0
votes
0
answers
357
views
State pattern in JPA
I need to implement a state pattern in JPA.
I'm working with a delivery System for products. I can create orders, each order contains an order status (for example: Sent, Delivered, Cancelled, etc), so ...
0
votes
0
answers
190
views
State VS Strategy design pattern
I really know that when we have a state-dependent behaviour, we automatically think of state design pattern, especially when it comes to a behaviour that changes according to the state and at the same ...
2
votes
1
answer
330
views
Knowing the state of an object using the state pattern
I am using the state pattern and I need to know in which state a given object is to print it. I thought about using an abstract method returning a string that each state would override with its own ...
1
vote
1
answer
190
views
Where to place an actor within the state pattern?
I have problems finding the right place for an actor and a timer used in a state machine.
I found some inspiration from this site about the state pattern:
State Design Pattern in Modern C++ and ...
1
vote
0
answers
776
views
Recursion using Flux
I have a scenario, where I am using the State pattern. Every Start has an Action defined. We start with an initial state and an initial Action and then keep going until the Action becomes null. If the ...
0
votes
1
answer
517
views
State Pattern: Changing object behavior based on more than one field and consistency between their values and state value
I'm Trying to learn about State Pattern.
In most of State Pattern examples that I have seen, methods of class change their behavior based on just one field (I mean before applying State Pattern and I'...
0
votes
1
answer
164
views
State pattern error in C++ (no suitable constructor)
class Tool {
public:
virtual void mouseUp();
virtual void mouseDown();
virtual ~Tool();
};
class SelectionTool : public Tool {
void mouseDown() override {
std::cout << &...
0
votes
1
answer
138
views
Segmentation fault when implementing state pattern in C++
I'm trying to implement State pattern in C++.
Here an example code:
#include <cstdio>
class Context;
class State {
public:
virtual ~State() = default;
explicit State(Context *context) ...
3
votes
1
answer
101
views
Broken encapsulation in State pattern in Java
I have implemented state pattern for my socket library in Java.
I simplified code to reduce size and increase readability just to demonstrate the problem.
I don't know how to encapsulate using of ...
1
vote
1
answer
2k
views
Difference between std::optional and boost::optional when its value is a variant
In embedded programming memory allocations are things that we want to avoid. So using design patterns like state design pattern is cumbersome. If we know how many states we will have then we can use ...
0
votes
1
answer
1k
views
Best way to construct complex states with state pattern?
I have a menu that can be in different states so I decided to use the state pattern. Reading online about the pattern seems like the usual way is to construct states from another state but this will ...
0
votes
0
answers
64
views
"friend" classes in C# and the state pattern [duplicate]
I was trying to implement the state pattern in C#, and I did something like this:
class Context {
private State state = null;
private State concreteState1 = null;
private State ...
0
votes
1
answer
78
views
object oriented programming: another way to implement state pattern?
I need help with another solution in this Object-oriented design challenge! The technical leader asked me to give another solution.
This is the challenge:
An Army is made up of units. A unit could be ...
1
vote
4
answers
712
views
Access from state class to private fields of context class
I am confused about state pattern implementation. Under this pattern, we should extract state management into separate classes. At first glance it allows us to avoid big if ... else ... constructions ...
5
votes
2
answers
3k
views
Using The State Pattern in games
Recently, I've tried to create Snake game in SFML. However, I also wanted to use some design pattern to make some good habits for future programming - it was The State Pattern. But - there is some ...
2
votes
1
answer
764
views
State Design Pattern: How to avoid code duplication when using entry() and exit()?
Situation: My States have an entry() and exit() method that needs to be called every time when a State transitions. To ensure that, I used a changeState() method in State that contains the necessary ...
0
votes
1
answer
1k
views
State Pattern in c#
I got into this book called "game programming patterns" and I started implementing some of its patterns in C#. Right now, I'm implementing the State Pattern which is described by the UML Class Diagram ...
5
votes
1
answer
133
views
Does it makes sense to use state pattern with virtual proxies?
class HeavyweightObjcet
{
public void operate() {
System.out.println("Operating...");
}
}
class LazyInitializer
{
HeavyweightObjcet objcet;
public void operate()
{
...
0
votes
0
answers
57
views
state design pattern - when a new state add to parent state, this cause another state also change, what do we do to prevent change another state
In state design pattern ,In the worst case when a new state is added to parent State, it causes all other states to change as well.
What changes need to be made to the design to prevent successive ...
1
vote
1
answer
866
views
State pattern vs Polymorphism
I'm new to design patterns, when I looked at the state class diagram, I found it's just a polymorphism applied. Nothing is special about it. Am I wrong?
0
votes
0
answers
286
views
Improving state design pattern with back-reference to the context
First of all I would like you to know that I read different topics about: cyclic import, cycling type hints and so on. According to this answer we can notice that:
States store a reference to the ...
2
votes
1
answer
307
views
How can I perform a cyclic state transition when using discriminated-unions's Match to represent state transitions in C#?
I'm experimenting with using discriminated unions in C# (specifically, using the excellent OneOf library) as means of representing and performing state transitions, taking advantage of compiler-...
2
votes
4
answers
6k
views
State Machine approach for simple state transitions
I am looking into creating a very simple state machine. My state machine will contain the following 3 states:
public enum States {
PENDING,
ACTIVE,
DONE
}
There are multiple transitions + ...
0
votes
1
answer
1k
views
Would I have to use Factory design pattern or State Design pattern
In my application a user would enter a link for an image or a video. According to the type of media (image, video or Pin from Pinterest) the app will determine how to display a thumbnail of the ...
2
votes
1
answer
874
views
Android Camera2 API with "State" Design Pattern
I've been working for 2 months with different Camera2 API projects. As you may know, Camera2 API is little difficult to understand and maintain, it requires some knowledge of multiprocessing, states ...
0
votes
1
answer
574
views
Implementation of the State Pattern
I have to implement a state machine with very basic requirement that every state pattern should have:
The state machine can be in any ONE state at a time.
The transition from X state to Y state will ...
3
votes
0
answers
304
views
State-dependent behaviour of Python objects using Ruby-like eigenclasses with mixins
I've been looking for a natural way to implement state-dependent behaviour (state machines) in Python objects. The goal was for objects to have a small number of states, or "mutually orthogonal" ...
3
votes
4
answers
5k
views
Why State Design Pattern over If-else
Everywhere I find people saying it is better to use state design pattern over if else. I want to know why:
It is an improvement to if-else in real world use case?
Does it make code more testable?
can ...
0
votes
1
answer
146
views
The difference between strategy and state design patterm, How a state is aware of its predecessor?
I read about state and strategy design patterns in refactoring.guru web site in pages State and Strategy. The author says
This structure may look similar to the Strategy pattern, but there’s one key ...
4
votes
2
answers
5k
views
State Pattern in Python
I am having some issues wrapping my head around on implementing the state design pattern in Python.
I am new to Python and wrote some code to try and answer this question that was presented to me:
...