-3

After learning about state machines, I want to place it in every class of my code. That's a great pleasure for me to declaratively (or "fluently") construct a machine, handle events and be sure that any logic violation will throw an exception.

Can you please critisize me on this practice? Or, may be, you install Stateless package habitually for each project (like I do)?

Any examples of state machines overusing?

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
astef
  • 8,575
  • 4
  • 56
  • 95
  • It's not clear what you are asking here. A state machine is a general concept. You talk about it as if it was a library of some kind. – Daniel Hilgarth May 14 '13 at 12:10
  • Every sentence before "?" sign is a question to answer. All of them describe a topic on which you can post your insight – astef May 14 '13 at 12:14
  • Well, I've used Stateless library and bbvcommon state machine. They are quite the same. – astef May 14 '13 at 12:22

1 Answers1

2

Whilst design-patterns are very good practice, you should be cutting code to solve a particular problem that potentially will use a design-pattern to solve that problem in a tried-and-tested manner.

We do not write code from a "let's use this design-pattern" perspective because a single design-pattern is not a one-size fits all solution!

Do not write all your code around the state machine idiom. It will make many simple tasks over-complicated and difficult to maintain.

Moo-Juice
  • 38,257
  • 10
  • 78
  • 128
  • But almost every problem require entities which must stay in a particular state. Almost everywhere those entities must change their state. Every project can contain a logical error in entities states and state machine is a best way to detect it – astef May 14 '13 at 12:17
  • 1
    @astef, then go ahead and ignore the advice and see how nasty your code-base becomes because you've decided to use state-machines *everywhere*. You've obviously already made your mind up, so go knock yourself out ;) – Moo-Juice May 14 '13 at 12:34
  • 1
    @astef: no, your wrong. State machines are used for really specific problems, not all. for example running a server with different states: connected/disconnected/connecting. But the UI of a program has nothing to do with states. Please read up on: http://www.skorks.com/2011/09/why-developers-never-use-state-machines/ and http://stackoverflow.com/questions/2183809/when-do-you-favor-the-use-of-state-machines-over-linear-workflows – RvdK May 14 '13 at 12:58