From: Friedrich Dominicus Date: 2002-09-17T15:52:55+09:00 Subject: Re: MVC and OO Design? jcb@iteris.com (MetalOne) writes: > Thanks to all for your help. > > I was really thinking very abstractly about a problem in my head that > MVC kind of demonstrated. I was in search of deep answers in regards > to when to include a function in a class and when not too. Ok now after a an abstract example an fully fledged Ruby MVC application. I've used ruby-gnome and This is the application code require 'lglade' class Controller def initialize @glade = GladeXML.new("mvc_ruby.glade"){|handler| method(handler)} @tf_1 = @glade.widget("tf_number_one") @tf_2 = @glade.widget("tf_number_two") @sum_field = @glade.widget("tf_sum"); @model = Model.new end def on_pb_calculate_clicked(widget, data) @sum = @model.add(@tf_1.get_text.to_f, @tf_2.get_text.to_f) @sum_field.set_text(@sum.to_s) end def quit Gtk.main_quit end end class Model def add (a, b) return a + b end end Controller.new Gtk.main The view is not seen as a extra class text here it's hidden behind the @glade instance variable that's my View! The .glade stuff is this (very fast thrown together, so please be aware: But please be aware too where the connection occures. - the names for the textfields - and the callback functon (enclosed in ...) This is what I would see as "exported" from the View. I do not claims this to be excelleent ruby programming but I hope it shows that MVC and OO do not fight each other. What could be improved the @tf_1.somethi.to_f chain is not nice one, one could hide it behin another function. But you are invited to do it better than me ;-) MVC_ruby mvc_ruby src pixmaps C True True GtkWindow main_window MVC Example in Ruby GTK_WINDOW_TOPLEVEL GTK_WIN_POS_NONE False False True False GtkVBox vbox1 False 0 GtkHBox hbox4 False 0 0 True True GtkLabel label4 GTK_JUSTIFY_CENTER False 0.5 0.5 0 0 0 False False GtkEntry tf_number_one True True True 0 4 False False GTK_PACK_END GtkHBox hbox5 False 0 0 True True GtkLabel label5 GTK_JUSTIFY_LEFT False 0.5 0.5 0 0 4 False False GtkEntry tf_number_two True True True 0 4 False False GTK_PACK_END GtkHBox hbox6 False 0 0 True True GtkLabel label6 GTK_JUSTIFY_CENTER False 0.5 0.5 0 0 4 False False GtkEntry tf_sum True True True 0 4 False True GTK_PACK_END GtkButton pb_calculate True clicked on_pb_calculate_clicked Tue, 17 Sep 2002 06:16:34 GMT GTK_RELIEF_NORMAL 5 False False Very verbose this XML isn't it ;-( Regards Friedrich