From: John Date: 2006-04-07T21:21:01+09:00 Subject: Re: Separation of gui from "real work" Stephen Tashiro wrote: > This is not a ruby specific topic but since there were some definite > opinions expressed about systems of writing GUIs in a recent thread, let > me ask it here. > > Is there a practical program architecture for separating the gui portion > of a program from the part that does the "real work"? Or is this just a > high flown idea that is rarely practical? You need to look into a concept called MVC - it stands for Model/View/Controller. The specifics vary from language to language but essentially, this technique carves your app into three sections: The MODEL defines your data structure. This could be the way it's stored in a database, or the file format if you're writing to a file. Ideally, you should be able to have as little as possible of the implementation-specific nature of whatever you use to be exposed. For example, if it's a music management app, don't have a method called "executeSql" exposed outside of the Model, because maybe you also want to store it in a file where SQL is not appropriate. Instead, implement methods for all the different tasks you might want to perform - adding songs, getting lists of songs by a particular artist, and so on. The VIEW is the user interface and all the associated logic for that. If you want to show the info in a tree view, like Windows Media Player (say, Artist>Album>Song), then you'd build the tree here. Finally, the CONTROLLER is the bit that handles all the complicated logic. Building a random playlist might happen in the CONTROLLER, for example. There is always some overlap, and there is necessarily some links between the different modules, but these should be kept limited and tightly controlled so that you know where to go if you want to swap, say, from an SQL database to a proprietary file format. A good example in Ruby is Rails, which also adds a HELPER section. This technique (as evidenced by Rails's HELPERs) is not set in stone, but it's a basis for you to build your apps on. Hope that helps -- Posted via http://www.ruby-forum.com/.