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

  • SEARCH
  • Home
  • 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 894239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:21:06+00:00 2026-05-15T14:21:06+00:00

Recently I was listening to a tech talk on clean coding. The speaker was

  • 0

Recently I was listening to a tech talk on clean coding. The speaker was a test engineer, who emphasized on avoiding the “if” statements in the code and use polymorphism as much as possible. Also he advocated against global states.

I quite agree with him, yet i need a clarification on replacing the global state and “if” statement using polymorphism for the below scenario,

I have 3 states in my document. I want to change the state of the UI components based on the document state. Right now, i use “if” blocks and an enumeration type holding the current state of document to transition the states of UI components.

eg:

enum DOC_STATE
{
DOC_STATE_A = 0,
DOC_STATE_B,
DOC_STATE_C
};

void QMainWindow::handleUi(_docState)
{
switch(_docState)
{
case (DOC_STATE_A):
{
menu.disable();
....
}
case (DOC_STATE_B):
{
menu.enable();
...
}
case (DOC_STATE_C):
{
...
}
}

I think i can have separate child classes for each state and have the handleUI() method in each class. Calling handleUi() method calls the right method call. But say i maintain these objects in my doc, how do i switch from one object to other each time there is a transition in state?

In other words, how to handle UI transition by tracking the change in state of document without using a global state and “if” or Switch statements?

I use Qt. Thanks.

  • 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-05-15T14:21:07+00:00Added an answer on May 15, 2026 at 2:21 pm

    If you are using Qt, take a look at The Qt State Machine Framework and the State Machine Examples. No need to re-invent the wheel when your framework already provides a sports car 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was listening to a podcast recently (may have been SO - can't remember)
Recently I was asked to develop an app, which basically is going to use
I was recently listening to a podcast which made a comment on using $()
I was recently advocating to a colleague that we replace some C# code that
I was listening to a podcast recently that was discussing at length the short
I have recently been introduced to ncurses for asynchronous keyboard key listening, and getting
Working on existing code, I recently found smt like this: if(Config.ExceptionBehavior.DEBUG_EXCEPTIONS) { foo.Foo(); }
I have recently implemented a MIDI Beatbox from the code in Head First Java
Recently I found some simple source code of a bootloader.The following is the simple
We recently had an issue where an advertiser who purchased advertisments via a 3rd

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.