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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:02:10+00:00 2026-05-23T13:02:10+00:00

I want to implement FSM like below First Level Most basic State is BASE_STATE.

  • 0

I want to implement FSM like below

  • First Level Most basic State is BASE_STATE. All
    states derive from BASE_STATE.
  • Second Level, WAITING_STATE,
    RUNNING_STATE, END_STATE, … so on
    (Derived from BASE_STATE. No new
    functionality)
  • Third level, There are 2 groups
    states (ACTIVE and PASSIVE),
    One-on-one matching for all second level states
    like

ACTIVE_WAITING_STATE , ACTIVE_RUNNING_STATE , ACTIVE_END_STATE, so on
PASSIVE_WAITING_STATE, PASSIVE_RUNNING_STATE, PASSIVE_END_STATE, so on

most functionalities are common for ACTIVE and PASSIVE states, just some small functions overrided. There is no problem until here. Problem is, All third level group have common functions. I mean, For example I have to implement 2 different increment() function one of is ACTIVE_xxx_STATEs, another one is PASSIVE_xxx_STATEs. How to do this without re-written for all states (eg. ACTIVE_WAITING_STATE , ACTIVE_RUNNING_STATE , ACTIVE_END_STATE, and also PASSIVE states)

To clearify my questions, my ugly sol’n. Problem is increment functions is same and re-written for all ActivexxxState (and also PassiveXXXState).

public class BaseState {
    // Lots of functions
}

public class WaitingState extends BaseState{
    // Lots of functions
}

public class RunningState extends BaseState{
    // Lots of functions
}

public class EndState extends BaseState{
    // Lots of functions
}

public Class ActiveWaitingState extends WaitingState {
     // Few unique functions
     private void increment() {
         System.out.println("increment active");
     }       
}


public Class ActiveRunningState extends RunningState {
     // Few unique functions
     private void increment() {
         System.out.println("increment active");
     }       
}

public Class ActiveEndState extends EndState {
     // Few unique functions
     private void increment() {
         System.out.println("increment active");
     }       
}

public Class PassiveWaitingState extends WaitingState {
     // Few unique functions        
     private void increment() {
         System.out.println("increment passive");
     }       
}

public Class PassiveRunningState extends RunningState {

     private void increment() {
         System.out.println("increment passive");
     }       
}

public Class PassiveEndState extends EndState {

     private void increment() {
         System.out.println("increment passive");
     }       
}
  • 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-23T13:02:10+00:00Added an answer on May 23, 2026 at 1:02 pm

    I would make increment() a protected method in BaseState so it is implemented once.


    I have written an article on using enums to build a state machine. This can avoid the need to create classes everywhere for each state and still support some inheritance.


    In answer to your comment.

    abstract class BaseState {
       public abstract boolean isPassive();
       public boolean increment() {
          System.out.println("increment "+(isPassize() ? "passive" : "active");
       }
    }
    
    class PassiveState {
       public boolean isPassive() { return true; }
    }
    

    If you don’t want to have multiple isPassive methods you could assume a class naming convention

    public boolean isPassive() { return getClass().getSimpleName().startsWith("Passive"); }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to implement a two-pass cache system: The first pass generates a PHP
I want to implement an ISAPI filter like feature using HttpModule in IIS7 running
I would like to implement a FSM/pushdown automaton parser for this syntax: parser with
I want to model a kind of FSM(Finite State Machine). I have a sequence
I Want Implement a Software by C#.net.I want Use a DataBase Manager Software like
I want implement paging same as safari in iphone.When user touch below button of
I want to implement like this: namespace PIMP.Web.TestForum.Models { public class ThreadModel : PagedList<T>
I want to implement the union, intersect, difference and reverse operations in Java. First
I want to implement animated text i.e. moving the text from bottom (half of
If all tables I want to delete from have the column gamer_id can i

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.