Skip to main content
Share Your Experience: Take the 2024 Developer Survey

Questions tagged [state]

The State pattern is used to represent the internal state of an object and to encapsulate varying behavior for the same object based on its state. This can be a cleaner way for an object to change its behavior at runtime without resorting to large monolithic conditional statements and thus improve maintainability.

Filter by
Sorted by
Tagged with
2 votes
1 answer
101 views

How to manage array of states effectively?

I have a working code to have 2 search bars with dropdown suggestions, selectable by both mouse and arrow keys in TypeScript and Fresh/Preact. In there I have to explicitly declare individual hooks ...
Ooker's user avatar
  • 201
2 votes
0 answers
201 views

Flutter Cubit: 2 Screens and Listview

I try to program a small app to track my cost spendings. As state management I use Cubit. As I am a flutter beginner, I wanted to verify if I implemented it correctly. The UI consists of 2 screens: 1 ...
Rasputin221's user avatar
-2 votes
2 answers
99 views

Is this a good way to advance one-by-one in an array of objects? [closed]

Using plain JavaScript, I want to load an array of objects, display the first one in a Bootstrap Card, and then click a button to advance to the next one. Focusing only on the point of getting the ...
AimFireReady's user avatar
2 votes
1 answer
73 views

Factory for state classes with varying numbers of reference data members

Consider the following code: ...
prestokeys's user avatar
  • 1,371
1 vote
1 answer
76 views

first React project - Lights Out game

I am working my way through a React tutorial on Scrimba (I am not finished yet). I got to a certain part that inspired me to try a project on my own. I made a game of Lights Out. If you've never heard ...
apex2022's user avatar
  • 161
3 votes
1 answer
391 views

Unit test for a React click-counting component

Take this basic component using state: ...
user8758206's user avatar
0 votes
1 answer
113 views

Doubling of state to speed up UI performance in React with Redux

I have a settings section to my UI which keeps track of a myriad of user settings. The settings are requested from an API when the app loads, and then used in the section to populate what the user's ...
Seth Lutske's user avatar
1 vote
1 answer
291 views

Another Vending Machine implementing State Pattern

I previously asked for a review for a Vending Machine implementing State Pattern in this linked post. And received an answer from @radarbob. The code below is my revised attempt based on some of @...
fourbeatcoder's user avatar
5 votes
1 answer
541 views

Vending Machine implementing State Pattern

I was asked to implement a Vending Machine in a recent interview coding challenge. My attempt at a solution is based on the state pattern. I would like to get some code reviews on this bearing in mind ...
fourbeatcoder's user avatar
6 votes
1 answer
2k views

Date range generator

An app has a feature that's much like any calendar application (like the Outlook calendar for example). Consequently, I need to do a lot of date logic. I wrote a class with date calculation methods ...
user2190492's user avatar
8 votes
1 answer
582 views

Haskell Tic-Tac-Toe (with automation and GUI)

There are already many Tic Tac Toe posts. But as far as I can tell, none of the ones in Haskell are complete with a GUI Here is my implementation with Gloss. Gist Link for convenience ...
Agnishom Chattopadhyay's user avatar
1 vote
1 answer
114 views

State monad and pattern matching on data constructors

I am writing a Settlers of Catan server in Haskell for fun. Currently I am passing around state manually. I want to learn more about the State monad and want to incorporate it into my project. However,...
The Coding Wombat's user avatar
7 votes
1 answer
408 views

A beginner's brainfuck interpreter in Haskell

I am rather new to haskell, and could use some feedback on my code and the decisions I had to make. In my previous project, I made a JSON parser, but relied heavily on guidance from a university ...
el_micha's user avatar
6 votes
0 answers
58 views

React state management design pattern new approach thoughts

Hey people on the internet! I do not know where to share my new npm package so I am asking you do you know of a good place to share my package? Also I would really appreciate if you take a look on it ...
erano's user avatar
  • 161
2 votes
0 answers
268 views

Storing localStorage data as part of rxjs reducer?

I use ngrx in my Angular app to state management. At a certain time I was asked to save some variable to local storage and retrieve it with first load. That made ...
noamyg's user avatar
  • 121
2 votes
0 answers
38 views

Switching article states using state pattern

The Article model supports a bunch of transitions. Only two are shown below: star()/unstar()....
lexeme's user avatar
  • 121
2 votes
0 answers
25 views

Custom Global Store using React.js context and hooks

I wanted to use an external global state to a React.js application with a redux-like sort of pattern (with reducers, actions, etc). However, I don't want to use redux itself, as it's just a small ...
thesilican's user avatar
2 votes
2 answers
509 views

Scalable design of a system with multiple state machines, where valid state transitions depend on the state of other machines

This is a pretty huge question, however, I would appreciate it if you could just review the design and not my implementations of it. The Implementation and test sections could be ignored, they are ...
Blue7's user avatar
  • 373
6 votes
4 answers
2k views

Section 2: Classes - Design a StackOverflow Post

Design a class called Post. This class models a StackOverflow post. It should have properties for title, description and the date/time it was created. We should be able to up-vote or down-vote a ...
Milliorn's user avatar
  • 620
3 votes
1 answer
117 views

Haskell - Caching third party API token across requests

The following code is designed to cache a (UTCTime, Text) value that keeps the Text token around until it expires, preventing ...
danbroooks's user avatar
4 votes
2 answers
430 views

Persisting Variables Over A State Loss

In an application that I built recently, I needed to persist several variables, without loosing their state, for duration that the application was in use. After some research, I found this post on ...
rickmanalexander's user avatar
2 votes
1 answer
138 views

Simpler state manament alternative to Redux, MobX, Context API, etc

I got frustrated with the jargon and created an alternative state management solution. Its up at https://github.com/smakazmi/react-soliit. It goes something like this ...
Ali Kazmi's user avatar
  • 271
1 vote
1 answer
1k views

Toggle between two options in an object?

I have just written this code for toggling between two possible states of an object. ...
AncientSwordRage's user avatar
2 votes
2 answers
83 views

N rotations of an array, either left or right, and then printing the result

Disclaimer, I'm new to OOP, but have experience in haskell and javascript. Essentially, the challenge was to create a program which would shift an array a given amount of times to the left and then ...
Dan Savage's user avatar
3 votes
3 answers
141 views

Cooking steak with State Pattern and without IFs

I've been playing around a bit with a case of State Pattern but including as well ranges in order to get into a specific state. So the definition is as simple as this: There is a Steak that has a ...
Facundo La Rocca's user avatar
1 vote
1 answer
40 views

View for logging telephone calls

As part of a web-based claims system I have created, there is a view for logging telephone calls. If a call is incoming, the claims handler asks the caller a series of data protection questions to ...
datahandler's user avatar
2 votes
1 answer
65 views

Checking user verification status

The User story is as follows: Users are allowed to get "verified", so other users know they have passed a background check. After tapping "get verified" button, or the "verification badge" ...
AnonProgrammer's user avatar
2 votes
2 answers
474 views

getDerivedStateFromProps [closed]

Starting from React 16.3 there are some new lifecycle methods introduced. One of them is the static getDerivedStateFromProps(props,state) method. This method ...
bvdb's user avatar
  • 133
4 votes
4 answers
2k views

State Pattern for traffic lights

I tried to implement a traffic light system using state pattern, please comment on the OOP/design pattern use. ...
Gilad's user avatar
  • 5,311
16 votes
0 answers
3k views

Realtime concurrent Haskell MIDI buffer

Problem Background MIDI is a serial representation of control signals to a sound generator. Typically, a noteOn message initiates the attack phase of a sound at a given pitch. The note will ...
user1441998's user avatar
1 vote
1 answer
249 views

Currency exchange app

I'm making a currency exchange app, it works as follows: User types in on desired currency input and the rest of the input fields change with state based on the currency value from the input used, I'...
ricardoNava's user avatar
6 votes
1 answer
749 views

State Monad in TypeScript

Here's my implementation of State Monad in TypeScript, based on a canonical Haskell implementation. I would like it to get code reviewed. ...
dark_ruby's user avatar
  • 193
1 vote
1 answer
64 views

Using an alternative for a switch/state-based custom parser

I'm currently developing a small tool that applies a number of regex-based match/replacement-pairs to the contents of a file (or, more generally speaking, a string). Note that regex-knowledge is not ...
PixelMaster's user avatar
0 votes
1 answer
5k views

Toggle between two states in react

I have two fetch calls which updates the state. And I have two buttons. One makes a fetch call, another calls componentDidMount()...
Mahade Walid's user avatar
8 votes
1 answer
820 views

Elegant output separators

Today I found myself reinventing output separators for the zillionth time. I have converged on an approach like the following that seem pretty clean: Live On Coliru ...
sehe's user avatar
  • 1,322
27 votes
3 answers
2k views

A Failable<T> that allows safe returning of exceptions

This was inspired by a conversation in chat, that started with the discussion of C#7.0 tuples and out parameter declarations, which led to the idea that there is no 'good1' way to return an error ...
Der Kommissar's user avatar
5 votes
1 answer
87 views

Logon state management

I'm in the process of writing a simple text based MUD. First up is making sure that it's possible to create new players / logon with existing players. Since everything is text based, there are ...
forsvarir's user avatar
  • 11.7k
3 votes
1 answer
113 views

ApplicationSettings Class for disabling/restoring Application State

This previous iteration of this question can be found here A utility class to handle the state of the Application object. Storing the application's initial state (...
Kaz's user avatar
  • 8,790
-2 votes
1 answer
73 views

Capture some state in Haskell

I want to capture some state in a Haskell function. For instance, I have many thread trying to print on the console and I want the to play nice with each other. So I want to have some XX to make the ...
nicolas's user avatar
  • 171
7 votes
2 answers
542 views

Evaluating Parser State

The "parser state" of a module in rubberduck can be one of several values: ...
Mathieu Guindon's user avatar
4 votes
1 answer
2k views

(C++14) Handling state in C-style function pointer callbacks

I'm having some issues coming up with a sensible solution for using shared state in a C-style function pointer. I am using GLFW to handle my OpenGL context and have created a thin wrapper around all ...
djrollins's user avatar
  • 143
5 votes
1 answer
2k views

Model of an mp3 player with state and prototype design patterns

After reading about design patterns in general, I decided to try and incorporate them in an actual program. I chose a State machine for my first exercise, or, more concretely, an MP3 player. The ...
Stefan Rendevski's user avatar
3 votes
1 answer
266 views

Is my design still a state design pattern, or some abomination?

I was trying to review state design pattern, and tried to create flexible implementation of it so it could reuse it in future. So I came out with this: ...
user902383's user avatar
8 votes
1 answer
614 views

HangPerson in Haskell

I created a HangPerson game in Haskell and I must admit it feels very imperative. How can I make it more "functional?" Are there more elegant ways of breaking up the task? The ...
Michael Chav's user avatar
7 votes
2 answers
17k views

Console application menu

Sometimes I need to write a simple Java console applications and menu look: ...
gstackoverflow's user avatar
5 votes
1 answer
376 views

Untouchable Numbers

I wrote this program in response to a CodeGolf challenge that required generating this sequence of "untouchable" numbers. This sequence can be found on OEIS as A005114. My initial implementation was ...
ankh-morpork's user avatar
3 votes
1 answer
565 views

Using C++11 move semantics to implement state pattern

I'm implementing a C++ layer on top of the sockets api of the OS (i.e. man 7 socket)1. Tcp sockets go through various states. Using the RAII principle leads to distinguishing the states: ...
Kasper van den Berg's user avatar
1 vote
1 answer
385 views

Managing state in Clojure

Where should you store state and how should it be managed in a ClojureScript application? Take the following code for example - it's a "game" where you travel either down or left. ...
adrianton3's user avatar
4 votes
1 answer
350 views

Huge terminal game (in development)

I'm developing a big (for me, as a beginner) terminal program "Brainfuck - The Game", in which you have to complete Brainfuck challenges. I would like your review on existing code (and project ...
user avatar
2 votes
1 answer
94 views

Polymorphic components for graphics and program state

I asked this question on StackOverflow, got some answers, most notably a link to this one, and basing on that I've implemented this: ...
Bartek Banachewicz's user avatar