Page 1 of 2

How I learn - MVC development model

Posted: Mon Apr 26, 2010 3:21 am
by leulae
I want to get the basic Idea of MVC development model, and Implement by me, There are more tutorials and examples, now I am in a big mess, want to study and implement it from the beginning,

Direct me to good site or to free eBook, it is better it has step by step instructions and examples


Thanks in advance

leulae

Re: How I learn - MVC development model

Posted: Mon Apr 26, 2010 8:45 am
by alex.barylski
If you absolutely must learn from the bottom up (I am the same way) the best way to learn is to build a MVC framework and post it here under code comments. Everyone will make comments as to best practices and how accurate your interpretation is, then you can apply those changes and feel the difference. Rinse and Repeat dozens of times and eventually you will get a solid MVC framework.

Re: How I learn - MVC development model

Posted: Mon Apr 26, 2010 9:01 am
by Eran
On the other hand, I'd recommend picking up an existing well-documented framework and learning how it works. I learn best by example, so that's what I would do.

Re: How I learn - MVC development model

Posted: Mon Apr 26, 2010 9:24 am
by matthijs
I'd do what Pytrin suggests. Start by looking at good existing frameworks and learning from a couple of good books. Then after a while when you have enough knowledge and experience you could start writing your own library.

It's like learning anything else, like playing the piano. First someone has to show you the moves, you start practicing basic exercises and only after you grasp the basics do you start to play yourself and experiment.

Writing your own MVC framework while having little to no knowledge of how it should be done is like starting to hit the piano without knowing any note. Maybe you'll learn to play in the end, but it'll take way too much time and you risk learning it the wrong way.

Re: How I learn - MVC development model

Posted: Mon Apr 26, 2010 10:34 am
by alex.barylski
Its clear from the above that everyone has a different learning style.

I have always prefered to learn systems from the inside out (low level core then high level API, etc). Thats just due to my nature of having to understand everything before commiting to any technology, etc. It will slow your productivity down however, because lower level details are of little interest to client developers. Same applies to a MVC framework. It's really of little to no interest to most developers how a front controller ticks, dispatches, etc so unless you have an insatiable(sp) desire to learn these details don't bother.

Cheers,
Alex

Re: How I learn - MVC development model

Posted: Mon Apr 26, 2010 11:43 am
by Eran
This is not about low-level versus high-level. It's about learning from others' experience instead of starting from zero and reinventing the wheel. You can go over the source for any framework and learn about approaches to all the elements you mentioned.

But you are right that everybody has their own way of learning.

Re: How I learn - MVC development model

Posted: Mon Apr 26, 2010 10:21 pm
by leulae
Thanks all, I will do, Thankfull if you can provide me little examples and good sites.

Leulae

Re: How I learn - MVC development model

Posted: Tue Apr 27, 2010 12:14 am
by PHPHorizons
I can direct you to a highly recommended author who is skilled in teaching programming to beginners (not necessarily read as "beginner in everything", but as a beginner in the particular area of the subject being taught).

Larry Ullman is the author of many programming books. I and many others have found his technique particularly helpful in learning things quickly.

Larry Ullman's 3 part blog on MVC

I haven't read that one yet, but I'll read at least the first part now, so if you want to talk about what's being said there, I'll know what ya talking about :P

Re: How I learn - MVC development model

Posted: Tue Apr 27, 2010 6:35 am
by Zyxist
Actually, 99% of web framework simplify the MVC model so much that it becomes MVP (Model-View-Presenter). Canonical MVC is a bit different. I point this out becasue when I switched to "professional" web frameworks a couple of year ago, I was wondering where all this legendary productivity is, if everything is done in exactly the same way I was programming earlier except that templates are called views, database calls via ORM/DAO - models and the rest of the code - controllers.

This is how the data are passed in MVP and web frameworks:

Model <--> Controller <--> View

So we take the data from model in the controller, and in the controller put them into the view. The so-called home-made scripts work much in the same way except that the three layers usually are not named "Model", "View" and "Controller" :).

This is how MVC is supposed to work:

Model <---> Controller
Controller <---> View
View <---> Model

So the controller selects the model and the view, and they communicate directly through some well-defined interfaces.

Another thing which makes me mad in web frameworks is reducing models to the ORM layer. And if I have an XML importer? If my models operate on a file system rather than a database? It happens, but from the web framework point of view they are not model which obviously breaks MVC rules.

Re: How I learn - MVC development model

Posted: Tue Apr 27, 2010 6:50 am
by Eran
It seems you have experience with a particular framework, since what you've written certainly does not apply to all PHP frameworks.

Re: How I learn - MVC development model

Posted: Tue Apr 27, 2010 8:16 am
by alex.barylski
This is not about low-level versus high-level. It's about learning from others' experience instead of starting from zero and reinventing the wheel. You can go over the source for any framework and learn about approaches to all the elements you mentioned.
I see learning low level versus high level as an inside out approach, learning internals before learning client usage. For instance before I fully accepted front controllers I had to see and build my own several times before it finally clicked and I accepted the solution as better than my (at the time) current solution.

That doesn't mean I did not look at how others did it, I just dug into the details extensively, as opposed to learning a framework from a high level, client developer persctive, I also gained insight from the framework developer perspective.
This is how MVC is supposed to work:

Model <---> Controller
Controller <---> View
View <---> Model
I am not sure I agree with this. MVP is typically used in heavy window'ing type frameworks, like that found in Windows. Controllers are typically heavier than in MVC.

Classical MVC (typically implemented in event systems) is where that dependency diagram comes from, passive view MVC (typically used by the web) does not share that same dependency:

http://martinfowler.com/eaaDev/PassiveScreen.html

Cheers,
Alex

Re: How I learn - MVC development model

Posted: Tue Apr 27, 2010 2:34 pm
by Christopher
leulae wrote:I want to get the basic Idea of MVC development model, and Implement by me,
The most important thing to learn is this: Your Models should not have dependencies on code in the Presentation Layer.
[text]Presentation Layer (VC)
|
V
Model Layer (M)[/text]
If you can start building your applications with clean separation between you Models and the Presentation code that manages input/output, then you will be 90% of the way to MVC. The View/Controller separation is easier and fuzzier. It is much more fun to argue about because it does not matter much.

Train yourself to design and build the Models first. Once you have done that, then implement the code to display them (the View) and to manage input (the Controller).

Re: How I learn - MVC development model

Posted: Wed Apr 28, 2010 10:14 am
by Zyxist
PCSpectra -> yes, and in popular web frameworks, controllers are also very heavy. In some of them the heaviness is hidden by some extra abstractions that have very little to do with MVC itself, but they work until you do not have to extend or modify them. I always followed the framework developers' guidelines and ended up with a code that was responsible for almost everything except direct database calls and HTML displaying. Guess what happened if there was a need to add new features i.e. to the CRUD displaying. It's not about where MVP is used but what the web framework developers produced, and they might want to produce MVC, but actually produced MVP. For me, reducing the model layer to ORM and removing the dependency between views and models drastically changes the properties of the design pattern, and we could all agree that design patterns were introduced to be sure that if we do as the pattern XXX recommends, we get certain properties and features. If the web framework developers do not implement classical MVC, they should write "Our framework implements MVP/Passive View MVC", not "Our framework implements MVC".

And by the way, my experience comes from five different and popular frameworks.

Re: How I learn - MVC development model

Posted: Thu Apr 29, 2010 12:58 am
by leulae
I found a site to learn the MVC, how about this lesson ...

Model View Controller in PHP
http://php-html.net/tutorials/model-vie ... er-in-php/

Re: How I learn - MVC development model

Posted: Thu Apr 29, 2010 1:57 am
by Christopher
It's a Page Controller essentially but the example does show the right dependencies.