Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,168,884 members, 7,872,908 topics. Date: Thursday, 27 June 2024 at 04:02 AM

MVC Pattern - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / MVC Pattern (2462 Views)

Free Csharp, Mvc, Jquery And More Tutorials Online / Pattern Chaser In Javascript: Coding Challenge / Download Asp.net Mvc 5 Essential Training Video Tutorial (2) (3) (4)

(1) (2) (Reply) (Go Down)

MVC Pattern by kencas: 8:44am On Mar 11, 2009
Hey Developers.Could any one elaborate more on MVC?
Re: MVC Pattern by logica(m): 12:56pm On Mar 11, 2009
Re: MVC Pattern by Seun(m): 6:33pm On Oct 26, 2009
A lot of time people say "MVC" when they really mean to say "separate your data access layer (SQL stuff) from your display layer (HTML, Javascript) and use a control layer (unique to your application) to glue them together." In other words, modular programming. MVC is a narrow term that is not applicable in most situations, but the idea of separating your data access from the UI is very sound and very important.
Re: MVC Pattern by candylips(m): 6:41pm On Oct 26, 2009
All coders should try to learn this pattern at the very least
Re: MVC Pattern by Seun(m): 6:46pm On Oct 26, 2009
candylips:

Any programmer that doesn't know or learn this pattern is a joke coder
It appears you didn't read what I wrote. What most people call MVC is not MVC at all.
The real MVC is not that widely applicable, and hence not very important. Whatever.
Re: MVC Pattern by candylips(m): 6:51pm On Oct 26, 2009
Seun MVC was actually built during the days of smalltalk so it has been around for quite a very long while

but never really got into the mainstream until a few years ago courtsey of various open source projects.

I'll say most frameworks in the major langugues incorporate this pattern in some way these days so an understanding of what the pattern is and why it is so important will make you a better programmer
Re: MVC Pattern by Seun(m): 6:55pm On Oct 26, 2009
I checked the wikipedia MVC page again and it seems the term has been redefined based on its erstwhile erroneous current usage, and not what it meant when the pattern was invented in the Smalltalk community.

If we define MVC based on what is there now, my argument fails completely. (If people use a term wrongly for a long time, it becomes correct. I guess that's how language evolves). So you're right, I guess.
Re: MVC Pattern by cdeveloper(m): 9:14pm On Oct 26, 2009
When i started out with programming my mentor an Indian once told me that in learning programming you do not just learn the syntax and semantic and then relax and feel like a programmer rather you strive to learn the philosophy ,the weakness and the strength the language cos at a point in your coding life you learn to apply the strengths of a language while keeping its weakness at a minimum.

My friend above posted a request wanting to know more about MVC pattern , perhaps it has captured his attention and all i could see was a reference to a wiki where he will find nothing but theories about MVC. Some say that MVC is not applicable in some areas i agree but if you ask me , the best pattern i have seen applicable to web developement is the same pattern we are talking about here MVC

Just like the name sound MVC,Model---View---Controller if  our notion of this pattern is simply the separation of app into three parts namely the Model(database etc), View(interface,html etc) and Controller(some serverside scripts etc) then we will not understand the true meaning of the pattern and when we do not understand that, then we can not use what we have limited know about. I must let the people here know that MVC is applicable not only in the serverside but also in the clientside with pure Javascript.

The birth of object oriented programming spawned  the idea of patterns, when developers keep getting the feeling "dejavour" (but i have done this before). Patterns, if i may paraphrase it, is a set of solutions for dealing with a known problem. It is an OOP way of dealing with problems and there are a lot of them.

The basic of an MVC app is simply objects that talk to each other through a well defined means with some rules applying to them this rules are simply that:

1. A view object does talk directly to the Model object
2. A Model object does not talk directly to the  View object
3. A controller object is the bridge between the View object and the Model object
4. if a view object needs data it makes request to the model object through the Controller object
5 If the Model object needs to send data to the View object it sends it through the Controller object

To put it in another way MVC is IOC(Inter-Object-Communication)
The Model
The model is like an end point from which you get a resource, this resource is not only a database, it could be a flat file, a web service, just about anything that has a form of storage capability can pass as a model.Meaning i could have a controller that is talking to a Flickr photo model etc.
The Controller
This is like a king whose duty is to issue commands or pass on messages from other objects. It could be a serverside script or even a Js function delegated to the task of contacting a serverside script via ajax.
The Views
The views are what there name imply but the are more than that. they are objects delegated with the task of constructing the actual interface that is render to a browser or a window GUI. They wait for response from the Controller and have there own logic for determining what to render and what not to render.In JS the are called event subscribers cos they are usually attached to a controller who will pass on the message from the model to them on completion.To put it in another, they are sometimes called template parsers. for those who no the Backbase framework and who have looked at the FB app developement markup language, this are the templates that are usually parsed by the View object
so if i say <fb:iframe width='400' height='400'>  etc ,i am only creating a template that will be parsed by the View object which will examing the custom tag <fb:iframe> and replace it with real iframe tag or translate it to some like this <iframe with='400' height='400'></iframe>

I have only explained what MVC means in ordinary sense of it but this pattern can be very simply or very complex depending on how you choose to implement it. A prime example implementation of the MVC pattern are the Zend Framework and the Symphony Framework. they did a great job with the MVC pattern. Perhaps i might someday  use real codes in both JS and serverside code to illustrate the MVC pattern in all its glory.
Re: MVC Pattern by doctorfox: 3:51am On Oct 28, 2009
Nice post cdeveloper. I was just going to skip this topic as with most of the others where most people choose to post "very useful" replies, but the last reply made sense.

The MVC pattern is most definitely the way forward for rapid application development.
Certainly its not the sort of thing you introduce to a beginner, but as time goes by and the need to scale up your application increases, you will discover that building your application in the MVC pattern will save you a lot of time as well as speed-up your software development life cycle.

For most of web developers, if you still write code with/without your own library of functions, you will still be limited by the regular syntax problems that crop up.

From experience I have tested several MVC frameworks, and the easiest one I think for PHP developers would be CakePHP.
For JavaScript, I would suggest you pick up any of JQuery or Dojo.

These frameworks have a large user/developer base and provide support and fixes.

You can Google any of these and find out more about them.

I'm sure there are a number of good developers out there and Nigerian IT/Software companies that utilise these frameworks.

Also, a good number of Nigerian web applications are built using the MVC pattern.

If you need to take your programming to another level, then try any of these frameworks. I'm PHP based so I'll recommend Zend framework and CakePHP for those in that area.

For some examples of web applications with an MVC framework check out; www.smartsms.tk, www.ebulksms.com,
If you have any other good examples please feel free to post them.
Re: MVC Pattern by Kobojunkie: 5:00am On Oct 28, 2009
candylips:

All coders should try to learn this pattern at the very least

Most of these frameworks are FADS. . . they are here today and no longer news tommorow. So, NO, you do not become a BETTER developer by learning yet another FAD. There is more to being a great developer than MVC.
Re: MVC Pattern by candylips(m): 12:16pm On Oct 28, 2009
well that is the unfortunate truth about Software development. It is like living on the fast lane .

Things get out of fashion very quickly

But looking at MVC from a software engineering perpective i think it is very sound design pattern which will outlive not only frameworks but also programming languagues
Re: MVC Pattern by logica(m): 12:41pm On Oct 28, 2009
Exactly, after all, OOP is supposed to be another fad isn't it? *light-bulb*
Re: MVC Pattern by candylips(m): 12:43pm On Oct 28, 2009
logica where have u been hibernating in spring since grin
Re: MVC Pattern by logica(m): 1:07pm On Oct 28, 2009
It's actually winter, which is the right time to Hibernate in a house standing on Struts, and each strut fitted with a Spring. tongue

If you have heard about "coupling" in programming (loosely coupled, tightly coupled, etc) then you can say MVC is loose coupling in action. I usually design applications along the line of a 3-tier application based on MVC. I always make it a point that I can completely delete my View layer (which is usually a Web Application Project), without having any errors (which of course would result if there were any dependencies) in my Model layer or Controller layer. That is 100% loose-coupling. With this design, the obvious advantage is I can completely replace my view component (with, say a newer and hopefully better interface), while keeping all the application logic (controller) and data design (model).
Re: MVC Pattern by Ghenghis(m): 2:31pm On Oct 28, 2009
In reality MVC can't be used as is for the stateless web. A variant called Model 2 is used.

The core abstraction of MVC is however, generally valid for most application needs .

Sun for instance uses a variant called Model-delegate.

The motivation for MVC is ,any kind of application that has an HCI (possibly multiple) and data.

MVC tries to isolate the parts of the system that change the most.
Re: MVC Pattern by Kobojunkie: 2:53pm On Oct 28, 2009
candylips:

well that is the unfortunate truth about Software development. It is like living on the fast lane .

Things get out of fashion very quickly

But looking at MVC from a software engineering perpective i think it is very sound design pattern which will outlive not only frameworks but also programming languagues

Do you know how many design patterns are out there today? The same could be said of those too.

Anyways, I have yet to run into any companies that places much emphasis on MVC pattern being used. Most just want fully functional and scalable program and leave the choosing of best fit patterns to the architect to come up with.

by the way @Logica, OOP is not a pattern, it is a programming paradigm, and not all shops use OOP. It all depends on your architectural design and where you want to go with it.
Re: MVC Pattern by Ghenghis(m): 3:06pm On Oct 28, 2009
Kobojunkie:

Most of these frameworks are FADS. . . they are here today and no longer news tommorow. So, NO, you do not become a BETTER developer by learning yet another FAD. There is more to being a great developer than MVC.

On one hand i agree with kobojunkie, There is more to being a great developer than MVC. There are many patterns that a developer can use to write robust, scalable and maintainable apps.

because Frameworks come and go, its better to be familiar with patterns ( which are like good solutions to some general kind of problem ), they'll stay with you.

all good developers should be familiar with the patterns of their domain ,

Patterns adds more magic to a developer's box of tricks cheesy
Re: MVC Pattern by logica(m): 3:07pm On Oct 28, 2009
. . . and where in my post did u see me refer to OOP as a pattern? U used the word "fad", which applies to patterns as well as paradigms.

And with the regards to companies not relying on MVC, I wonder what you think frameworks such as Struts, Ruby on Rails etc are based? You don't have to directly implement MVC (or MVC2) in your application most of the time; it's already there!
Re: MVC Pattern by Kobojunkie: 3:10pm On Oct 28, 2009
OOP was introduced so many odd years ago, but it is  just another paradigm among many out there that could be applied in architecting your solution. By Fad I mean a style that many are interested in it at first, but as time goes on, groups realize that there might be something better out there for what they need, or what they already have in place is better and stick with it. So, it is not an INDUSTRY-WIDE accepted standard of some sort.
Re: MVC Pattern by logica(m): 3:12pm On Oct 28, 2009
. . . well then, it would seem you are not well acquainted with how widely MVC is used. Let's just leave it @ that.
Re: MVC Pattern by Kobojunkie: 3:20pm On Oct 28, 2009
logica:

. . . and where in my post did u see me refer to OOP as a pattern? U used the word "fad", which applies to patterns as well as paradigms.

And with the regards to companies not relying on MVC, I wonder what you think frameworks such as Struts, Ruby on Rails etc are based? You don't have to directly implement MVC (or MVC2) in your application most of the time; it's already there!

That too! If you worked in .NET for instance, on studying the library, you would notice quickly that you don't even have to consciously work on using a pattern because the framework itself is built combining various patterns, from provider, factory, bridge, singleton, composite etc. You just need to use what you want, and boom!! you can claim you are using a pattern! lol . I like what I learned from my mentor back some years ago. He said "Keep it simple!". As long as you are able to get necessary results one way, you do not have to pursue other ways unless necessary.


logica:

. . . well then, it would seem you are not well acquainted with how widely MVC is used. Let's just leave it @ that.

If that is what you want to believe, that is fine by me. I am just stating that developers ought not to go out of their way to learn MVC just cause someone deems it the alpha and omega of his programming life. grin
Re: MVC Pattern by logica(m): 3:25pm On Oct 28, 2009
Well, guy, I hope you are aware there are several "layers" of Software Development. You should be aware that it's people who developed such frameworks as Struts, meaning they had to implement the MVC pattern on which Struts is based. Not all developers are only focused on using frameworks; some actually build them. *light-bulb*
Re: MVC Pattern by Ghenghis(m): 3:32pm On Oct 28, 2009
Kobojunkie:

That too! If you worked in .NET for instance, on studying the library, you would notice quickly that you don't even have to consciously work on using a pattern because the framework itself is built combining various patterns, from provider, factory, bridge, singleton, composite etc. You just need to use what you want, and boom!! you can claim you are using a pattern! lol . I like what I learned from my mentor back some years ago. He said "Keep it simple!". As long as you are able to get necessary results one way, you do not have to pursue other ways unless necessary.


Yeah .NET implements many patterns in the base class libraries, but only a handful and the simple ones. There are many programming need that requires more than instantiating a singleton or using an iterator. And there are so many patterns besides the ones Identified by GOF, i particularly like the leaky bucket of credits pattern.



Kobojunkie:

If that is what you want to believe, that is fine by me. I am just stating that developers ought not to go out of their way to learn MVC just cause someone deems it the alpha and omega of his programming life.  grin
I agree the poster was a little dramatic about MVC, but that does not remove from the wisdom of using patterns. There's a saying about standing on the shoulder of giants - that's what a developer that uses patterns gets!

logica:

Well, guy, I hope you are aware there are several "layers" of Software Development. You should be aware that it's people who developed such frameworks as Struts, meaning they had to implement the MVC pattern on which Struts is based. Not all developers are only focused on using frameworks; some actually build them. *light-bulb*

True, but knowing the patterns that the framework uses might allow a developer to understand the intent of the framework, so you get less abuse or erroneous constructs. You'll be able to do things the right way. (You can definitely write un-MVC with struts if you are stubborn enough) grin
Re: MVC Pattern by logica(m): 3:39pm On Oct 28, 2009
You don't seem to understand. I am more interested in developing a framework like Struts for others to use, than simply be a user of frameworks. Meaning I have to have a firm understanding of design patterns. That was the point I was making. Any developer that does not want to limit himself to merely being a framework user will definitely get well acquainted with patterns.
Re: MVC Pattern by Kobojunkie: 3:46pm On Oct 28, 2009
I was addressing the topic of the thread, not development of frameworks. The statement that was made was not in reference to those trying to develop their own frameworks. Even when it comes to developing frameworks, knowledge of design patterns will work well on your behalf but you will likely not APPLY ALL patterns out there, even MVC in developing your framework.
Re: MVC Pattern by Seun(m): 10:07pm On Oct 28, 2009
Since we're all kissing MVC's ass here, let me add mine. MVC is the entire essence of software development.
The real reason Vista failed is because they didn't implement MVC correctly. MVC is all there is. MVC is God.
Re: MVC Pattern by logica(m): 10:25pm On Oct 28, 2009
@Kobojunkie

Your post made the assumption that all developers only aspire to be framework users, and will likely not develop frameworks themselves. But even then, while developing simple systems (framework or no framework), I don't see why you shouldn't aspire to code as cleanly, elegantly and efficiently as possible (which is why we use patterns in the first place).
Re: MVC Pattern by Kobojunkie: 1:54am On Oct 29, 2009
logica:

@Kobojunkie

Your post made the assumption that all developers only aspire to be framework users, and will likely not develop frameworks themselves. But even then, while developing simple systems (framework or no framework), I don't see why you shouldn't aspire to code as cleanly, elegantly and efficiently as possible (which is why we use patterns in the first place).

I have never entertained the thought that all developers ONLY aspire to be framework users, so NO, I never made that assumption.

There are 1000s of ways to get clean and elegant code WITHOUT implementing MVC pattern.
Re: MVC Pattern by logica(m): 2:22am On Oct 29, 2009
How about you mention a few. Then we will proceed by actually coming up with real problems and then you code the solution, while I use an MVC based framework. We then compare my solution to yours?
Re: MVC Pattern by Kobojunkie: 2:40am On Oct 29, 2009
logica:

How about you mention a few. Then we will proceed by actually coming up with real problems and then you code the solution, while I use an MVC based framework. We then compare my solution to yours?

Dude, this is NOT about some test of wits or coding here.

  In my work as a contractor,  I have yet to work on a single team where MVC has been used to date, and I am talking of fortune 500 companies. I work in .NET world, and even the new ASP.NET MVC framework is still not an industry wide standard considering most shops and software houses are still comfortable working with what they have since it works and is clean and good for them. Are we to assume these companies do not have talented developers on staff then? Are these applications to be considered non-functional simply because no consideration was made for MVC pattern? Again, like every other design pattern out there, it has it's place. It is not FOR ALL development, framework and non.


I recently worked on a piece creating custom modules for a web based application and the company has their piece buiilt using classic asp and vbscript. We are talking in the year 2009 , and there are no plans to switch over to asp.net anytime soon.
Re: MVC Pattern by logica(m): 2:56am On Oct 29, 2009
I was hoping you'd put your knowledge where your keyboard+mouse+finger is, but it's whatever. I am a very practical person, and trust me when I say I'd rather prove points practically than exchange posts all day. Ciao.
Re: MVC Pattern by Kobojunkie: 3:15am On Oct 29, 2009
I am sorry, I am not here for an EGO contest of any kind.  I prefer we focus on facts, rather than play the MY CODE IS BETTER THAN YOURS game even here in Nairaland.

(1) (2) (Reply)

Enquiry On Accessing Bank Transfer API / Final Year Project Topic In Mechanical Software Application / I Need Help On Oop Project Using C# Console-base Application

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 71
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.