Flow-Design Cheat Sheet – Part II, Translation
Posted
by Ralf Westphal
on Geeks with Blogs
See other posts from Geeks with Blogs
or by Ralf Westphal
Published on Sun, 20 Mar 2011 16:02:15 GMT
Indexed on
2011/03/20
19:22 UTC
Read the original article
Hit count: 357
In my previous post I summarized the notation for Flow-Design (FD) diagrams. Now is the time to show you how to translate those diagrams into code. Hopefully you feel how different this is from UML. UML leaves you alone with your sequence diagram or component diagram or activity diagram. They leave it to you how to translate your elaborate design into code. Or maybe UML thinks it´s so easy no further explanations are needed? I don´t know. I just know that, as soon as people stop designing with UML and start coding, things end up to be very different from the design. And that´s bad. That degrades graphical designs to just time waste on paper (or some designer). I even believe that´s the reason why most programmers view textual source code as the only and single source of truth. Design and code usually do not match.
FD is trying to change that. It wants to make true design a first class method in every developers toolchest. For that the first prerequisite is to be able to easily translate any design into code. Mechanically, without thinking. Even a compiler could do it :-) (More of that in some other article.)
Translating to Methods
The first translation I want to show you is for small designs. When you start using FD you should translate your diagrams like this.
Functional units become methods. That´s it. An input-pin becomes a method parameter, an output-pin becomes a return value:
The above is a part. But a board can be translated likewise and calls the nested FUs in order:
In any case be sure to keep the board method clear of any and all business logic. It should not contain any control structures like if, switch, or a loop. Boards do just one thing: calling nested functional units in proper sequence.
What about multiple input-pins? Try to avoid them. Replace them with a join returning a tuple:
What about multiple output-pins? Try to avoid them. Or return a tuple. Or use out-parameters:
But as I said, this simple translation is for simple designs only.
Splits and joins are easily done with method translation:
All pretty straightforward, isn´t it.
But what about wires, named pins, entry points, explicit dependencies? I suggest you don´t use this kind of translation when your designs need these features.
Translating to methods is for small scale designs like you might do once you´re working on the implementation of a part of a larger design. Or maybe for a code kata you´re doing in your local coding dojo. Instead of doing TDD try doing FD and translate your design into methods. You´ll see that way it´s much easier to work collaboratively on designs, remember them more easily, keep them clean, and lessen the need for refactoring.
Translating to Events
[coming soon]
© Geeks with Blogs or respective owner