EKB This gives an example of what I think is a particularly Tcl-ish use of Model / View / Controller. I use this frequently in my own work and it certainly makes it easier to incrementally develop an application.
The architecture is pretty basic, something like this:
+--------------------+ | | | Core Program | | | +---------+----------+ | | / \ / \ / \ Mini- GUI(s) language/ CLI
The core program has no user interface capability. It just has programmatic hooks. In MVC, it is the model. Usually I use Snit for this.
Because this is Tcl, building the model, as a program with hooks, is basically a mini-language. It is easy to implement using a command-line program that just gives access to the program. The program itself is the controller and the command-line is the view (at least, I think this is a correct interpretation of MVC).
Although I often don't have to go to the next step, the MVC pattern makes it very easy to access the model via a Tk GUI, which would involve a further controller (a layer between the GUI code and the model) and the view (the GUI itself).
First, here's the command-line controller, to show how basic it is. It just calls the core program, which is inside the two files "crop.tcl" and "yield.tcl":
package require snit source "crop.tcl" source "yield.tcl" if {$argc != 1} { puts "Usage:" puts " yield inputfile.yld" puts "" puts "Your file is \"inputfile.yld\". It does not have" puts "to have a .yld extension, but must have all of" puts "the elements required for a yield input file." exit } namespace eval yield { source [lindex $argv 0] } # Run it! yield::run
enter categories here |
---|