Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8950579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:28:56+00:00 2026-06-15T13:28:56+00:00

I want to implement the GUI as a state machine. I think there are

  • 0

I want to implement the GUI as a state machine. I think there are some benefits and some drawbacks of doing this, but this is not the topic of this questions.

After some reading about this I found several ways of modeling a state machine in C++ and I stuck on 2, but I don’t know what method may fit better for GUI modeling.

  1. Represent the State Machine as a list of states with following methods:

    • OnEvent(...);
    • OnEnterState(...);
    • OnExitState(...);

    From StateMachine::OnEvent(...) I forward the event to CurrentState::OnEvent(...) and here the decision to make a transition or not is made. On transition I call CurrentState::OnExitState(...), NewState::OnEnterState() and CurrentState = NewState;

    With this approach the state will be tightly coupled with actions, but State might get complicated when from one state I can go to multiple states and I have to take different actions for different transitions.

  2. Represent the state machine as list of transitions with following properties:

    • InitialState
    • FinalState
    • OnEvent(...)
    • DoTransition(...)

    From StateMachine::OnEvent(...) I forward the event to all transitions where InitialState has same value as CurrentState in the state machine. If the transition condition is met the loop is stopped, DoTransition method is called and CurrentState set to Transition::FinalState.

    With this approach Transition will be very simple, but the number of transition count might get very high. Also it will become harder to track what actions will be done when one state receives an event.

What approach do you think is better for GUI modeling. Do you know other representations that may be better for my problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T13:28:57+00:00Added an answer on June 15, 2026 at 1:28 pm

    Here is a third option:

    • Represent the state machine as a transition matrix
      • Matrix column index represents a state
      • Matrix row index represents a symbol (see below)
      • Matrix cell represents the state machihe should transit to. This could be both new state or the same state
      • Every state has OnEvent method which returns a symbol

    From StateMachine::OnEvent(...) events are forwarded to State::OnEvent which returns a symbol – a result of execution. StateMachine then based on current state and returned symbol decides whether

    • Transition to different state must be made, or
    • Current state is preserved
    • Optionally, if transition is made, OnExitState and OnEnterState is called for a corresponsing states

    Example matrix for 3 states and 3 symbols

    0 1 2
    1 2 0
    2 0 1
    

    In this example if if machine is in any od the states (0,1,2) and State::OnEvent returns symbol 0 (first row in the matrix) – it stays in the same state

    Second row says, that if current state is 0 and returned symbol is 1 transition is made to state 1. For state 1 -> state 2 and for state 2 -> state 0.

    Similary third row says that for symbol 2, state 0-> state 2, state 1 -> state 0, state 2 -> state 1

    The point of this being:

    1. Number of symbols will likely be much lower than that of states.
    2. States are not aware of each other
    3. All transition are controlled from one point, so the moment you want to handle symbol DB_ERROR differently to NETWORK_ERROR you just change the transition table and don’t touch states implementation.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am re-designing some GUI items and want to implement something like the following:
My problem is I want to implement a GUI screen which will show some
I want implement in my software solution an VBA editor but in c# 3.0.
i starter in jqgrid, i want implement inline edit in jqgrid i have this
given this class definition: public class Frame { IFrameStream CapturedFrom; } I want implement
I want to implement a simple script to do some boring housekeeping on my
I want to implement something similar to MAC OS X Time Machine in terms
I want to implement or use some library for an intelligent decimal cut off.
im trying to implement a nice gui for organizing posts. i want to use
I want to implement some functionality in a library and make it available as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.