没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
State Machine Design Pattern
Anatoly Shalyto
Head of Programming
Technologies Department
St. Petersburg State University of
Information Technologies,
Mechanics and Optics
14 Sablinskaya Street
Saint-Petersburg, Russia 197101
shalyto@mail.ifmo.ru
Nikita Shamgunov
Software Design Engineer, SQL
Server Engine, Microsoft,
11407 183rd Pl NE #M1071
USA 98052, Redmond, WA
u04921@mail.ru
Georgy Korneev
Assistant Professor of
Programming Technologies
Department
St. Petersburg State University of
Information Technologies,
Mechanics and Optics
14 Sablinskaya Street
Saint-Petersburg, Russia 197101
kgeorgiy@rain.ifmo.ru
ABSTRACT
This paper presents a new object-oriented design pattern — State Machine design pattern. This pattern extends
capabilities of State design pattern. These patterns allow an object to alter its behavior when its internal state
changes. Introduced event-driven approach loosens coupling. Thus automata could be constructed from
independent state classes. The classes designed with State Machine pattern are more reusable than ones designed
with State pattern.
Keywords
design, pattern, automaton, automata, finite automata, finite state machine, behavior, state, transition, state chart
1. INTRODUCTION
Finite automata have been widely used in
programming since the appearance of [Kle56] which
introduced regular expressions and proved an
equivalence of a finite automaton and of a regular
expression.
Another area where finite automata are widely used is
object oriented programming, in which they are used
to design object logic. In this area states that have
major impacts on object’s behavior (control states)
are being extracted. Note that these automata are
significantly different from those used for regular
expression matching. In particular, objects are
designed in terms of interfaces and methods (terms
that don’t exist in classical automata) not in terms of
recognizable strings. This paper discusses automata
that are used in OOP.
In OOP, when people think of object behavior, they
consider the functionality of its methods. But in many
real world applications this definition is insufficient
— the internal state of an object should also be
considered.
The most famous implementation of an object whose
behavior depends on its state is the State pattern
[Gamma98]. However, pattern description is far from
being complete, in different sources [Ster01, Gra02]
it is implemented in different ways, sometimes even
too verbose. Another disadvantage of the pattern is
that the implementation of states in different classes
causes distribution of the transition logic among these
classes. This adds dependencies between the state
classes which lead to different issues in class
hierarchies design. In spite of these issues State
pattern is used in many practical projects including
JDO [JDO01].
This paper addresses issues of State pattern by
introducing a new pattern named State Machine. Note
that [San95] introduced a pattern with the same name
for parallel system programming in Ada95 but still
the authors have chosen this name.
To make reuse of state classes possible we introduce
an event mechanism. Events are used to let the
automaton know that the state should be changed.
This allows centralization of the automaton transition
logic and loosens coupling between state classes.
Permission to make digital or hard copies of all or part of
this work for personal or classroom use is granted without
fee provided that copies are not made or distributed for
profit or commercial advantage and that copies bear this
notice and the full citation on the first page. To copy
otherwise, or republish, to post on servers or to redistribute
to lists, requires prior specific permission and/or a fee.
Copyright UNION Agency – Science Press,
Plzen, Czech Republic
资源评论
- jiangjinsong2017-08-25权当学习资料 一般般
wzhanglibra
- 粉丝: 0
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功