Skip to content

JimRoepcke/RCSFSM

Repository files navigation

RCSFSM

Finite State Machines (FSM) and Pushdown Automata (PDA), modelled with Objective-C, using the GOF's State Design pattern.

Initially developed for a project in a graduate Distributed Systems course, later refined in a graduate Design Patterns course. Since then I've used this in commercial projects.

Better documentation will be provided as time allows, for now, here is a brief description of what you'll find here.

Usage Requirements

This code requires ARC and is known to work with iOS 5.x and later in Xcode 4.5 and later.


Finite State Machines

<RCSStateContext> protocol

An object that has a current FSM state.

<RCSState> protocol

A state in a FSM. <RCSState> objects are intended to be stateless, shared objects - flyweights.

Define methods on your state objects that transition its <RCSStateContext> to another state.

RCSBaseState class

Default implementation of the <RCSState> protocol.


Pushdown Automata

<RCSPushdownContext> protocol

An object that has a current PDA state.

<RCSPushdownState> protocol

A state in a PDA. This is useful when you multiple states need to be able to transition to a single state, and that state needs to be able to "go back" to whichever one transitioned to it. Rather than having a combinatorial explosion in the number of states to facilitate this, things stay simple by pushing the common state and defining a transition that pops back.

Define methods on your pushdown state objects that transition and push its to another pushdown state.

RCSBasePushdownState class

Default implementation of the <RCSPushdownState> protocol.


Example FSMs

RCSTask <RCSStateContext>

Respresents a task that uses a FSM to coordinate itself - an alternative to NSOperation that you can use to model a complex multi-state process. This is provided an example, but it is quite useful and was written for a production iOS app.

RCSTaskState : RCSBaseState

FSM states for a RCSTask.

##RCSTaskQueue <RCSStateContext, RCSTaskDelegate>

Represents a queue that undestands the semantics of RCSTask - a lightweight alternative to NSOperationQueue.

RCSTaskQueueState : RCSBaseState

FSM states for a RCSTaskQueue.

About

Finite State Machines for Objective-C

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published