Brief analysis of the principle of state machine and its important application

Source: Internet
Author: User
Tags abstract

If the business is a human body, then the state machine is like a person's soul. If a soul is not clear, do anything will be confused, if his brain clearly understand, do anything can be a step in place. The
Applied state machine can be briefly outlined as: Apply from a useless unstable state, migrate continuously, and migrate consistently to a useful problem state. An application can have many state machines, and can be correlated or unrelated between different state machines.
as a code of agriculture according to my abstract ability is really not what it is, and I was born in the family, so I always put complex and abstract problems simplification, materialization, vernacular, I am afraid that others can not understand. Today I will vernacular another technology.
An application only so can be strung up, moving to have a soul, is how to achieve the specific business logic, the best way to achieve is the state machine.
An application has a complete lifecycle from initiation to completion, and it is in a stable state for most of the entire life, and we call it steady, and he's sure to go through all the instability before going into the steady state. A state machine is a global variable that marks a constant migration from an unstable state and finally into a problem state. Of course the stable state is mutual, he will also migrate from the stable state to the unstable state, and finally migrated to this stable state. Such as: Application just started at the landing in the initial state (when there is a landing failure to enter the landing failure state, this state can not), when the landing is successful in the landing state (stable state), then you can carry out a variety of operations. When you are tired of trying to change an account, quit it, then you go into the state of not landing (because you are in this state usually can not do the core of things, so you can not call it a stable state), when you log on again, you enter the successful state of landing. When you exit the application, you don't have to record it. This is the simplest landing state machine. A similar order state machine, such as a receipt business. Some applications should be based on some pages at that time, when the application is closed and then open the application, to enter the last page. This works best with a state machine. In fact, many people in a variety of complex ways to implement the state machine, not in the simplest direct way to achieve. The simplest and straightforward description of a
state machine is to record the different states of an application with a global variable of an enumerated type, to enter different pages or to handle different logic depending on the global variable. An application can have different state machines (global variables of different enumerated types), and global variables of enumerated types can be logged to a file or database (for example, objects store core dat or file Sandbox, MFC object persistence is stored in the database), The next login can read the global variables for this enumeration type and jump to different pages and processes.
I do an app's network triggered automatic logon state machine enumeration type:

typedef ns_enum (nsinteger,login_state) {
    login_state_init = 0,
    login_state_login_sucess,
    login_state_ Logining,
    Login_state_unauto_login,
    login_state_unnet_login,
    login_state_exit_login
};

I do an app's network triggered automatic login state machine logic diagram:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.