poeschlorn
poeschlorn

Reputation: 12440

Implement a finite state automaton in OOP

I am thinking about implementing a program with finite state automaton in an OOP language like Java or C++.

What would you think is the best way to implement this with a manageable amount of available states, regarding to good software design?

Is it good to implement for each state an own class? If yes, how to do the bridge between two states?

Thanks for any comment!

Upvotes: 1

Views: 1866

Answers (3)

ChrisBlom
ChrisBlom

Reputation: 1279

The dk.brics.automaton library is good implementation of FSA's in Java. It's build with performance in mind, so it trades in some OOP principles for speed, but i'd recommend you take a look at it.

Upvotes: 0

Wudang
Wudang

Reputation: 555

Try this - the section on design is good and it shows a use for a fsm http://www.ibm.com/developerworks/library/wa-finitemach1/

Another use I've seen is to implement managed objects for a computer service, with the transition "start" moving the object from the "down" to the "starting" state etc using an extennsion of the OMG managed object life-cycle

Upvotes: 0

Java Drinker
Java Drinker

Reputation: 3167

Is this just to flex your programming muscle, or for an actual project etc? In either case it depends on what you want the state machine for: - is it to manage tasks in some sort of workflow - is it to determine application flow state - is it for a business rules engine etc

In the case of a project, I would suggest that, depending on what your target use is, you look for libraries in that domain. Java for example has MANY MANY libraries for workflow/busines flows, as well as tons of rules engines (Drools comes to mind right of the bat, although it is a complex behemoth)

Upvotes: 2

Related Questions