From: Bob Hutchison Date: 2008-11-09T01:58:53+09:00 Subject: Re: implementing mvc - using observer pattern - beginner to OOP Hi, On 8-Nov-08, at 12:57 AM, Adam Akhtar wrote: > Hi I started making a simple command line todo list application as a > way > to get better at OOP. I decided to use a flat file db gem called > kirbybase. > > Anyway the more I started programming it, the more it started to > resemble spaghetti code with ui getting mixed in with logic so I > started > using google to find some patterns that might help. > > One that came up was MVC which ive heard about from my very very > limited > rails experience. This is pretty much what MVC tries to deal with. There are variations on MVC as well. > > > I tried implementing it (more like fudging it) but I dont think im > giong > abotu it the right way. Ive looked on google for ruby specific stuff > but > keep getting rails results that only provide an overview of it. > > Can anyone provide any light on how to go about implementing it. You would have had better luck looking into the smalltalk world for MVC than the ruby world. These two papers are pretty good I think. The second paper talks about two kinds of model: application and domain -- this is important. Then read about value objects/models here: Value models seem like a bit of a pain, but worth knowing about. You won't likely need them at the start, and MVC + value models can be a bit complicated, but when your application starts getting complex they can help. As Jean-François pointed out, you don't have to do this yourself. On the other hand, if you are looking to learn OOP this is a pretty good way, it might be a hard way, but you'll certainly have a handle on OOP by the time you're done :-) > > > Will Kirby Base essentially be my model? Or will the model interact > with > kirbybase? MVC is an *object oriented* thing. So your model will interact with kirbybase. The rest of your questions are better answered by the papers I linked to. Cheers, Bob > > > If i use the observer pattern I guess the model should be the > observable > with the views being registerd observers. Right? > > What about the controller? What is it obesvign and who is observing > it? > > All menues etc will live in the views i think with user choices e..g > "add task" being registered in the controller along with the program > logic... is that right? > > Regards to their interaction, do all talk to each other or is there a > chain of command. I.e. the models seem to speak to the views by > updating > them, the controllers seem to talk to about the views and models? is > that right? > > Finally does the singleton pattern come into play here? If i wrap the > database into a class should only one instance be made? > > Apologies for my inexperience ;-) > > I know this may sound like overkill for a simply todo command line app > but i think it will make great practice and setme up for rails in the > future. > > any help will be of great assistance > -- > Posted via http://www.ruby-forum.com/. >