Objects and Machines

— Christopher R. Genovese

Announcements #

  • HW2 (classification-tree-basic) is now online
  • Office Hours: Thu 3-4, plus by Appt
  • Questions?

Plan #

  1. Finish Sprint Activity: State Machines
  2. Object-Oriented Programming

Sprint Activity: State Machines #

Specification #

The state of a system is a description of the system’s configuration at a particular moment. It typically captures the features of interest for a particular model or analysis, and in many cases, the future evolution of the system depends only on the current state.

A state machine is an abstract model of computation, a device that can be in one state at a time and transitions among states in response to external events, possibly producing effects or actions at a transition.

The task today is to write a small library for defining, representing, and “running” state machines.

There are four basic data entities/types in this system:

  • States
  • Transitions
  • Actions
  • Events

Your library should provide mechanisms to

  1. create a state machine,
  2. define states and events,
  3. specify the legal transitions among those states,
  4. associate actions with transitions,
  5. associate transitions with events, and
  6. given a state machine, “run” the machine by dispatching events.

Examples:

  • Traffic Light
  • Vending Machine
  • Pattern in a String

Design Discussion #

States #

  • What data should be embodied in a state?
  • How might we construct a state?
  • Can there be more than one initial state?
  • Should we handle product and sum states specially?
  • Where should actions be stored?
  • How might we capture the idea of a final/accepting state?

Transitions #

  • What data does a transition need to hold?
  • Guard conditions on transitions?
  • When can an associated action be applied in a transition? Must we select one of these?

Actions #

  • What are actions as data?
  • What information should be passed to an action?
  • Is raising an error ok in an action?

Events #

  • What is the essential information in an event?
  • What is the signature of event dispatch?
  • Do events trigger immediately/synchronously? What if resulting actions take a while? Do we need a queue?
  • Can we run more than one machine in parallel?
  • How do we type events?

Operations #

  • What operations do we need to support on these entities?
  • What are the types of these operations?
  • What does are main entry point look like?

Implementation #

Goal: Working implementation in an hour; pair up to share the load

Object-Oriented Programming #

Primer here.