MVC architecture ROCKS!

With my most recent project I decided to take the time to implement a proper MVC (Model-View-Controller) architectural design. At first I was very skeptical, thinking that the extra time required to design and implement a MVC architecture, would not add much benefit.

Was I pleasantly surprised to discover, that a properly designed MVC architecture makes it so much easier to maintain and expand a software solution. Every moment invested in taking time to design a MVC architecture is now paying back itself ten-fold.

I absolutely love to “wing” software projects, without spending too much time on design. However, after experiencing what a positive difference a good design makes, I’m starting to rethink my ways.

This also got me thinking… are there any other good software architecture patterns that I’ve missed over the years?

What’s your thoughts on design patterns? Do you like/dislike MVC, or perhaps had success in your own projects using a different design pattern?

Alwyn - I know you have nothing but free time (tongue in cheek) but I’d love to see a post mortem of your project. Perhaps an article in XDev Magazine. It would be an interesting read. I’m one of those who can read about and understand things such as design patterns, however, implementation within the Xojo context is often a struggle for me.

With MVC it is easy to use TDD It saves a lot of time in future too.

Since I need to document the project anyway, I’ll try to put together some sort of a summary on how I applied MVC design to the project, and post the result here. Writing a full magazine article on the topic is just outside of my time reach at this point… :wink:

Test-driven development looks like a great way to improve the quality of software. Below is an interesting chart that illustrates how the cost to fix a bug increases the further down the line you are with the development stages of your product/project… so by logical deduction… the sooner you catch the bug… the better it is for your business.

Full article

I’d be interested to. I thought view and controller pretty much go together in Xojo but I’d be happy to be shown a better way …

[quote]Since I need to document the project anyway, I’ll try to put together some sort of a summary on how I applied MVC design to the project, and post the result here. Writing a full magazine article on the topic is just outside of my time reach at this point… :wink:
[/quote]

I too am very interested in learning Xojo MVC design.
Thank you for sharing Alwyn and thank you for putting it here and not in xDev.

I used to subscribe to xDev but the reason I stopped was two main things :

I can’t stand starting to read an article of something I need to learn or something of interest then having to wait two months for the next issue to get the second half of the tutorial/article.

I don’t understand how developers learn like that. When I need answers I can’t waste my time sitting around for two months to get them.

The next reason I dropped my subscription was not enough xojo programming content in my opinion.

If issue one isn’t fixed to have complete articles in the same issue then I’ll never repurchase xDev again because honestly I can search the internet and find it myself in less time and don’t have to wait two months for the next issue.

For me to take it seriously I need to have the articles complete in each issue.

I’d also not buy a single issue for the $9.99 asking price mainly because there aren’t complete articles in there but I do feel that price is too high.
That would mean I’d be paying $20.00 (the price of an entire book) just for a single article that’s wanted.
It doesn’t make any sense to me personally.
I think the price should be lowered to $25/year and $4.50 an issue but that’s my opinion.

Have things changed since I was a subscriber and the articles now are complete in each issue?

There is an old example in the Realbasic section of my website at http://www.mothsoftware.com/content/realbasic/ :
Head First Design Patterns. Pretty old but should still work.

Ok, so my project was developed using PHP with jQuery Mobile as primary “view”. Since a few people asked for an example, I translated the idea into a Xojo project. After looking at the MVC example in Beatrix’s project I’ve come to realize there is probably lots of different ways to implement MVC in your projects, and you’ll have to decide on a way that is most comfortable for you.

This is my first attempt at MVC in Xojo, so please chirp in if you spot improvements that can be made. First, here is a diagram of how I envision the MVC process…

The goal of MVC is to separate your data from your view (presentation). All the user interaction is handled by the controller. Models are basically your data sources, and views are your presentation part of the system.

The controller retrieves data from the model, and then uses a view object to render this data into a presentable format (e.g. HTML). So in what format is data passed between the model and the view? I prefer to use JSON because it is lightweight, easy to work with, and can be extended without breaking compatibility with existing models and views.

So, onto a practical Xojo example… you can download the Xojo project here.

From the combo-boxes simply select the model and view you want to use and then click the “List Products” button. The output is rendered as text into a TextArea control. So what is the advantage of writing the program this way?

You can now add new models and views, without affecting the rest of the program. For example, let’s assume a new exciting database, named “AwesomeDB”, enters the market. All you have to do to make your program compatible with AwesomeDB is to write a new AwesomeDB model. Your views are unaffected and doesn’t even know about the new database addition.

And vesa versa… let’s say you currently output your view as HTML, but decided that you also want to output it as a PDF report… all you have to do is build a new PDFView object, and your models doesn’t even know about the fact that the data they provide are rendered as PDF documents.

Hope this helps those new to MVC. I’m still learning myself about how to use the MVC design pattern in my projects.

Thanks Alwyn. I appreciate this, and all your other examples (3d, mongo, etc. etc.) :slight_smile: