From: "Guerry A. Semones" Date: 2001-03-10T02:44:22+09:00 Subject: [ruby-talk:12342] Re: Understanding Design Patterns Was: GUI Toolkit for Ruby > While someone could possibly build a really generic interface to all of > the libraries, I'd suggest that a clean separation between the > presentation logic and everything else is a better way to go. > > The Facade design pattern kind of explains this, but it is shown much > better in Martin Fowler's "Analysis Patterns" book. The idea is that you > provide a Facade that can be used to drive your application. Then you > craft whatever user interface you want (Command line or GUI) and that > then drives the application using the methods exposed by the Facade. > > If you do this right it is then a relatively simple task to put a > different user interface on the application. This happens to be precisely what Ben Tilley was asking for in his recent post to the GUI discussion. I wholeheartedly agree. The Facade pattern according to Fowler: "A facade is a type that provides a simplified interface to a complicated model" (Analysis Patterns, p.247). The Model-View-Controller (MVC) pattern essentially tries to separate the model (data and logic) and the view (UI) with a controller (which knows about both). Please don't anyone slam my definition, I'm sure its not sufficient, but I've got the flu and other such excuses :-). By combining the two, you get some really excellent benefits. As you said one can swap out the UI or provide multiple UI in front of the business logic. Also (here's my addition) one can write tests against the business logic and not have to worry about testing business logic tangled in the GUI. Most simply put, the GUI should not do much more than delegate calls to non-GUI classes that do the real work. The GUI code should deal with GUI issues, the business logic should deal with business logic. We are currently doing a project where we've done just this. All business logic and validation are done separate from the GUI, and the GUI just delegates back. Most of the core business also delegates back to a mid-tier. The core point, however, is that we will be taking the business and validation logic and put it, unchanged, into an MVC designed web architecture: same code, same tests, different interfaces. Thanks, Guerry -- G. Semones, gsemones@treenleaf.com, http://www.treenleaf.com Code Ruby (http://www.ruby-lang.org) Ride the Cluetrain (http://www.cluetrain.com) "That's the spirit! Forward Momentum." -- Miles Vorkosigan