Chapter 8. Refactoring to Cairngorm
First, resist the opportunity to scatter state all over your application as strings, numbers, Booleans, and all manner of other primitive objects.
Steven Webster[1]
In this iteration, we’ll refactor the Flex code to use Cairngorm with HTTPService. We’ll use Cairngorm in a slightly nonstandard way, to be slightly less verbose and more aligned with the design preferences of Rails. (This book won’t attempt to explain “How to Use Cairngorm in the Standard Way.” (Of course, there’s not really a “standard way” any more, now that Cairngorm has been split into Cairngorm and Cairngorm Enterprise.) To learn the standard way of using Cairngorm, see the Cairngorm documentation.)
Note that Cairngorm is tough to explain in both an iterative and enjoyable fashion, because it has so many moving parts that work together. Furthermore, we’re going to use some utility classes to make our use of Cairngorm less verbose. Rather than do the refactoring in this iteration iteratively, I’ll present the finished result of the refactoring and explain the code all at once. As you see more and more of the code, you’ll see how it all fits together—so don’t worry if why we’re doing something isn’t 100% apparent at the time: By the end of the iteration, it will be.