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 6819221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:16:48+00:00 2026-05-26T21:16:48+00:00

I want state diagram states to be values of given enum type . In

  • 0

I want state diagram states to be values of given enum type. In the second step I’d like to use the state diagram as constraint for a property of previously mentioned enum type, e.g. as argument check in the property’s setter.

  • 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-26T21:16:49+00:00Added an answer on May 26, 2026 at 9:16 pm

    Still not sure I completely understand what you’re trying to achieve. Here’s some thoughts however, hope they’re useful. Apologies if I’ve missed the point.

    The first question is: why do you want the enum values and states to be isomorphic? In the most general sense that’s replicating information. And replicated information has a habit of getting out of sync. So it would be useful to understand the motivation.

    Notwithstanding, here’s a couple of possibilities.

    1. UML / Modelling perspective

    In the UML world there’s no real need to have both a state model and an enum associated with it. UML in general doesn’t define how to read the value of an object’s current state; however certain profiles (e.g. Executable UML) do. In Executable UML, any class that has a state machine automatically gets a read-only attribute named current_state. The possible values for current_state are the names of the states in the state model. So you could view it as the state machine defining an implicit enum.

    Note the attribute is read only. That’s because the only way to change it is through the state machine, i.e. by sending events to the object. So it also satisfies your second requirement: it’s not possible to change the value of the current_state variable in a way that violates the state machine protocol.

    Even if you’re not using the Executable UML profile (or similar) it’s perfectly valid to state the above as a rule/convention. If necessary you could define your own profile, although that might be overkill – depends on your circumstances.

    The key point is the enum isn’t necessary in the modelling world.

    2. Code Perspective

    When Translating the model to code, an enum is a sensible and common way to define the type for the current state variable. Per the modelling scenario, you’d want to make the current_state attribute read only to the outside world. You then need three other things:

    1. An implementation of the state machine
    2. public member functions for each of the events that drive the state machine
    3. A private member function for updating the current_state variable from within the state machine implementation.

    So in the code world, you prevent invalid sequences of the current_state variable by making it read only to the outside world. That is, you only have a public read accessor: there’s no public write accessor.

    Inside the class, you make the write accessor private and ensure the only place it gets called is within the state machine implementation.

    Instead of a public write accessor, you provide public methods corresponding to the events that drive the state machine. More detail on implementing state machines below, but here’s a trivial example for now:

    class Phone {
    
        enum PhoneState {disconnected, connecting, connected, disconnecting};
    
        public PhoneState current_state {get};  //no write accessor
    
        //functions for generating state machine events
        public void digit(int number) {..}      //press digit key, e.g. while dialing
        public void connect() {..}    //make connection
        public void disconnect() {..} //disconnect
    }
    

    Implementing the State Machine

    There are 3 common patterns for implementing state machines:
    1. State Matrix or Lookup Table
    2. Nested Switch
    3. State Pattern

    There’s a good overview of (1) here; (2) & (3) are covered here.

    And that’s basically it. Not entirely sure I answered your question. If not apologies, perhaps you could be more specific about what you’re trying to achieve.

    hth.

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

Sidebar

Related Questions

I want to set the type of the state parameter, of a state monad
I use a static enum in an interface and want to use it in
Ok - I'm feeling like a frustrated idiot. I want to state that upfront.
I want to retrieve state from a function object. But the function object has
I want to change the state of an ImageView in the items of a
I want to ensure that a WCF-ServiceClient State will be closed after using the
I want to check some things about the state of the session, the user
i want to make a tri-state checkbox inside listview control, iam using image list
i want to create a simple state machine using C but all the events
When I want to save some state behavior of the activity, The docs says

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.