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 ...
3
votes
1answer
39 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 (...
-2
votes
1answer
29 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 ...
7
votes
2answers
493 views
Evaluating Parser State
The "parser state" of a module in rubberduck can be one of several values:
...
1
vote
0answers
81 views
Managing the state of multiple, similar, selects in React Form
I have a really simple form with 3 select boxes for days, hours, and minutes (in the full code I have a submit button attached to an ajax request). And I've got each of those select boxes attached to ...
4
votes
1answer
193 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 ...
5
votes
1answer
185 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 ...
3
votes
1answer
155 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:
...
8
votes
1answer
169 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 ...
5
votes
2answers
798 views
Console application menu
Sometimes I need to write a simple Java console applications and menu look:
...
5
votes
1answer
97 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 ...
3
votes
1answer
153 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: ...
1
vote
1answer
137 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.
...
4
votes
1answer
254 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 ...
2
votes
1answer
64 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:
...
2
votes
1answer
255 views
Reading and Writing object from files
I have a server which has a permanent state which has to be saved on stable storage. It is composed by three fields:
List<LogEntry> log
...
3
votes
0answers
101 views
ThreeJS State Object
state object - a state or scene from the game. When the start function is called, the state starts rendering, shutting down any other state using the renderer, and calling the specified functions (...
4
votes
1answer
101 views
Encapsulated state in clojure
While going through SICP and trying to implement the code in clojure, I've found that while I can get the code in chapter 3 to work, it seems to go against Clojure idioms, but I can't quite imagine ...
4
votes
1answer
111 views
Simple attribute parser for HTML
I am studying Java and trying to write an HTML parser, which should parse tag names and attributes. I wrote a class (code below) using the State pattern.
This is necessary for my training project, ...
2
votes
0answers
34 views
Expressing computations on values as State
I was writing an application with a few Monads in a transformer stack. The top level application state resides in a TVar, and various components of the application ...
8
votes
3answers
380 views
Handling shared state among a lot of elements in Angular
I am working on a project in Angular where I have a number of similar data objects. When you click on anyone of them it's state and amount of data shown will change. All of the objects start in the ...
7
votes
4answers
287 views
Memory usage in Reversi board state
I'm coding a Reversi game, with an artificial intelligence using the MinMax as the search algorithm. My concern is that (most) search algorithms needs to store a lot of instances of "states", in my ...
2
votes
1answer
531 views
Simple Javascript state management class
So I needed very basic state management and notification for a small game-like thing I'm building. I decided to implement something like a finite state machine (but not quite, it doesn't transition ...
4
votes
2answers
81 views
Static variable representing program state accessed with multiple functions
I have this method that performs certain functions based on the state that the algorithm is currently at:
...
2
votes
2answers
325 views
Counting occurrences of Char8s in a file
To learn some Data.Map and Control.Monad.State, I have written the following code, which should count the occurrences of ...
3
votes
0answers
241 views
jQuery Plugin - HTML5 History State
I've built this small jQuery plugin to work with HTML5 History State functions. It's my first jQuery plugin, so I'm not sure if it's up to the best practices, or what could be done better. Keeping it ...
5
votes
1answer
243 views
A variant of state pattern + C++ template FSM without state creation/destruction penalty
This is a variant of the solution posted here, without state creation/destruction penalty.
Note that my comment in the original question about the simplification provided by C++11's inherited ...
12
votes
1answer
16k views
State pattern + C++ template
This finds its origin in the following reflection. In their book from 1995, the so-called gang of four (GoF) described the state pattern. What they were actually telling us in their description, is ...
7
votes
2answers
2k views
Developing a better state pattern in C
I have created a state diagram to show the different transitions and states. I could not find many examples of the state pattern in C, so I have taken an example from a Java state pattern and tried to ...
1
vote
2answers
111 views
What do you think about such code organization?
I'm working on mobile app which doing requests to servers API. I want to develop module that doing following:
get authorization key already exists in previous session
connect to server api and read ...
0
votes
2answers
79 views
Ruby OO design : how to handle inconsistent state in a mutable class?
Abstract
I'd like to have advice on how to :
implement methods that rely on a state,
when the instance is mutable and may be in an inconsistent state,
in such a way that the methods either ...
2
votes
1answer
178 views
Vocabulary trainer passing around too much IO/State
I've written a vocabulary trainer which does a lot of passing state around, as I have an ACID-database and a temporary state.
In my experience with Haskell I've learnt that overusing ...
5
votes
1answer
110 views
Finite State Automaton implementation
I've been studying compiler construction theory. Right now, I'm studying Finite State Automaton and I've tried to create my own implementation. I'm not sure if my implementation is right.
...
5
votes
1answer
444 views
Monkey testing a SmartCard library
My definition of monkey testing is basically playing with a program in as if I was a monkey (press every button, unplug things, go in the wrong order..etc etc)
So I made a rather simple SmartCard ...
12
votes
2answers
377 views
Handling game states for an online RPG game
I'm writing an ORPG. The code below is client-side.
I have a main thread looping in Game::Run:
...
6
votes
1answer
299 views
Usage of state machine to model lifetime of an IP address
I need to model an IP address and thought using a state machine (the state_machine gem) would be a good idea.
An IP has the following characteristics:
It is assigned to a server.
It can be in ...
4
votes
2answers
203 views
Using Booleans to Manage State
I'm in the middle of writing my own little bullet shooter game much in the style of Touhou. Everything works fine so far but I'm disliking certain aspects of my code. Take this function for showing ...