artima.com

Part I. Objects
People-Oriented API Design
by Bill Venners

<<  Page 5 of 20  >>

Advertisement
ad

Guideline 3. Understand the kinship between objects and state machines

In Guideline 2, I suggest you think of objects as machines. To get a better feel for the object as machine metaphor, I think it's helpful to look at the relationship between objects and state machines. Among the most useful insights that originally helped me get a feel for object design was that many objects act like state machines. You can think of all objects as machines. The kind of machine mutable service-oriented objects most resemble, mathematically speaking at least, is the state machine.

The Nature of the Machine

A state machine is defined by:

When a state machine is in some way built and put into motion, it starts out its lifetime in its initial state. At any time during its life it has a current state. The outside world interacts with the state machine by sending it messages. When the state machine receives a message, it performs actions, including potentially changing state.

Similarly, when an object is instantiated, it begins its lifetime in some initial state, established by the object's constructor. At any time during its life, it has a current state. The outside world interacts with the object by invoking its methods. When a method is invoked, the object performs actions, including potentially changing state, and then returns.

<<  Page 5 of 20  >>

People-Oriented API Design | Contents | Book List | Print | Email | First Page | Previous | Next

Sponsored Links
Download Artima SuiteRunner Now - It's FREE!

Last Updated: Sunday, May 11, 2003
Copyright © 1996-2003 Artima Software, Inc. All Rights Reserved.
URL: http://www.artima.com/objectdesign/object5.html
Artima.com is created by Bill Venners