- 论坛徽章:
- 0
|
and harder to change in response to user requirements, and it means that trying to change
policy has a strong tendency to destabilize the mechanisms.
On the other hand, by separating the two we make it possible to experiment with new policy
without breaking mechanisms. We also make it much easier to write good tests for the
mechanism (policy, because it ages so quickly, often does not justify the investment)
This design rule has wide application outside of the GUI context. In general, it implies that
we should look for ways to separate interfaces from engines.
One way to do this, for example, is to write your application as a library of C service routines
that are driven by an embedded scripting language, with the application flow of control
written in the scripting language rather than C. A classic example of this pattern is the Emacs
editor, which uses an embedded Lisp interpreter to control editing primitives written in C.
We discuss this style of design in Chapter 11 (User Interfaces).
Another way is to separate your application into cooperating front-end and back-end
processes communicating via a specialized application protocol over sockets; we discuss this
kind of design in Chapters 5 (Textuality) and 6 (Multiprogramming). The front end
implements policy, the back end mechanism. The global complexity of the pair will often be
far lower than that of a single-process monolith implementing the same functions, reducing
your vulnerability to bugs and lowering life-cycle costs.
Rule of Optimization: Prototype before polishing. Get it
working before you optimize it.
The most basic argument for prototyping first is Kernighan & Plauger's; 鈥 |
|