Why MVC?

23
WHY MVC? Wayne Tun Myint (Myanmar Web Solution )

description

This is my presentation for Developer Conference Myanmar 2013. It explains about the benefits and usages of MVC Architecture Design Pattern)

Transcript of Why MVC?

Page 1: Why MVC?

WHY MVC?Wayne Tun Myint

(Myanmar Web Solution )

Page 2: Why MVC?

What is MVC?

Model–view–controllerModel–view–controller

A software architecture pattern which separates the A software architecture pattern which separates the representation of information from the user's interaction representation of information from the user's interaction with it.with it.

The model consists of application data, business rules, The model consists of application data, business rules, logic, and functions.logic, and functions.

A view can be any output representation of data, such A view can be any output representation of data, such as a chart or a diagram.Multiple views of the same data as a chart or a diagram.Multiple views of the same data are possible, such as a bar chart for management and a are possible, such as a bar chart for management and a tabular view for accountants. tabular view for accountants.

Page 3: Why MVC?

How MVC works!

Page 4: Why MVC?

How MVC Works | Page 2

Page 5: Why MVC?

Brief History Of MVCMVC was one of the first works to describe and MVC was one of the first works to describe and implement software constructs in terms of their implement software constructs in terms of their responsibilities.responsibilities.

Trygve Reenskaug introduced MVC in the 1970sTrygve Reenskaug introduced MVC in the 1970s

In the 1980s, Jim Althoff and others In the 1980s, Jim Althoff and others implemented a version of MVC .implemented a version of MVC .

MVC was expressed as a general concept, in a MVC was expressed as a general concept, in a 1988 article.1988 article.

Page 6: Why MVC?

Brief History Of MVC- Page 2

The Controller, in modern applications is a module, The Controller, in modern applications is a module, or an intermediary section of code, that mediates or an intermediary section of code, that mediates communication (between the Model and View) and communication (between the Model and View) and unifies validation.unifies validation.

Other aspects of the MVC also evolved, but as a Other aspects of the MVC also evolved, but as a variant of the original concept.variant of the original concept.

HMVC, MVA, MVP, MVVM, and others that adapted HMVC, MVA, MVP, MVVM, and others that adapted MVC to different contexts.MVC to different contexts.

Page 7: Why MVC?

Father of MVCTrygve Mikkjel Heyerdahl Reenskaug Trygve Mikkjel Heyerdahl Reenskaug (born 1930 | Age 83) is a Norwegian (born 1930 | Age 83) is a Norwegian computer scientist and professor computer scientist and professor emeritus of the University of Oslo.emeritus of the University of Oslo.

He formulated the model-view-He formulated the model-view-controller (MVC) pattern for Graphic controller (MVC) pattern for Graphic User Interface (GUI) software design in User Interface (GUI) software design in 1979 while visiting the Xerox Palo Alto 1979 while visiting the Xerox Palo Alto Research Center (PARC). Research Center (PARC).

Page 8: Why MVC?

Some MVC Frameworks

Django (Python)Django (Python)

Rails(Ruby)Rails(Ruby)

Zend Framework (PHP)Zend Framework (PHP)

CodeIgniter (PHP)CodeIgniter (PHP)

CakePHP(PHP)CakePHP(PHP)

Page 9: Why MVC?

Some MVC Frameworks-2

YII (PHP)YII (PHP)

Laravel(PHP)Laravel(PHP)

Fuel PHP(PHP)Fuel PHP(PHP)

ASP.NET MVCASP.NET MVC

Laravel (PHP)Laravel (PHP)

Symfony(PHP)Symfony(PHP)

Kohana(HMVC) (PHP)Kohana(HMVC) (PHP)

Page 10: Why MVC?

WHY MVC?

MVC (Model – View – Controller) is one of those MVC (Model – View – Controller) is one of those concepts that only starts to make sense when you’re concepts that only starts to make sense when you’re dealing with larger applications and/or when working dealing with larger applications and/or when working on the same application with several developers.on the same application with several developers.

If you’ve got 3 tasks that need to be done on a If you’ve got 3 tasks that need to be done on a certain date, you won’t feel the need to have some certain date, you won’t feel the need to have some kind of task organization, but if you have to deal with kind of task organization, but if you have to deal with dozens of different tasks, with various due dates dozens of different tasks, with various due dates you’ll start using todo-lists. you’ll start using todo-lists.

)

Page 11: Why MVC?

WHY MVC-Page 2

But when you start working with a team of But when you start working with a team of people and you need to prioritize and people and you need to prioritize and sequence tasks, you realize simple to do-lists sequence tasks, you realize simple to do-lists won’t be enough.won’t be enough.

MVC’s benefits are absolutely not restricted to MVC’s benefits are absolutely not restricted to large-scale, team-based development, but they large-scale, team-based development, but they become most obvious in such situations.become most obvious in such situations.

Page 12: Why MVC?

Example Project Case You made an web application/website for a flower shop You made an web application/website for a flower shop owner with a small database table. it is a huge success owner with a small database table. it is a huge success and your client is extremely satisfied.and your client is extremely satisfied.

They ask you to change the application, they want to They ask you to change the application, they want to use a different database and according to market use a different database and according to market demand they definitely need both iPhone and Android demand they definitely need both iPhone and Android app as well.app as well.

Now repeat this five times. The client keeps on asking Now repeat this five times. The client keeps on asking modifications. expansions etc. modifications. expansions etc.

These can be UI related changes and even complete These can be UI related changes and even complete backend architecture .backend architecture .

Page 13: Why MVC?

YES , YOU will be in deep shit of pains.

However if you used MVC from the start you’d However if you used MVC from the start you’d notice that some things would’ve been less notice that some things would’ve been less painfulpainful

And more happier And more happier

Page 14: Why MVC?

Why?

90% of the code for the web application and the 90% of the code for the web application and the mobile app will be the same, but instead of saving mobile app will be the same, but instead of saving the user data to a Shared Object or through a web the user data to a Shared Object or through a web service, you’d be using a local DB for instance.service, you’d be using a local DB for instance.

Without MVC chances are pretty high you’ll be Without MVC chances are pretty high you’ll be making modifications in a bunch of classes.making modifications in a bunch of classes.

The same applies to the UI for instance. Only the The same applies to the UI for instance. Only the way it’s presented to the user is different. way it’s presented to the user is different.

Page 15: Why MVC?

Advantages of Using MVC

More StructuralMore Structural

More FlexibleMore Flexible

Can maintain code in better ways.Can maintain code in better ways.

More suitable for future implementationsMore suitable for future implementations

Reduce ComplexityReduce Complexity

Page 16: Why MVC?

Disadvantages

The complexity is high to develop the applications The complexity is high to develop the applications using this pattern without learning properly.using this pattern without learning properly.

Not right suitable for extra-small applications .Not right suitable for extra-small applications .

The isolated development process by UI authors, The isolated development process by UI authors, business logic authors and controller authors may business logic authors and controller authors may leads to delay in their respective modules leads to delay in their respective modules development.development.

Page 17: Why MVC?

CodeIgniterCodeIgniter is an open source rapid development web application framework, for use in building dynamic web sites with PHP.

“Its goal is to enable [developers] to develop projects much faster than writing code from scratch, by providing a rich set of libraries for commonly needed tasks, as well as a simple interface and logical structure to access these libraries.

First Version was released on February 28, 2006.

CodeIgniter is loosely based on the popular Model-View-Controller development pattern.

Page 18: Why MVC?

Code Igniter | Page-2

While view and controller classes are a necessary part of development under CodeIgniter, models are optional.

CodeIgniter is most often noted for its speed when compared to other PHP frameworks.

In a critical take on PHP frameworks in general, PHP creator Rasmus Lerdorf spoke at frOSCon in August 2008, noting that he liked CodeIgniter "because it is faster, lighter and the least like a framework.

Page 19: Why MVC?

Practical Code Example

Page 20: Why MVC?

Conclusion

Page 21: Why MVC?

References

http://stackoverflow.com/questions/24450/what-are-the-best-mvc-web-frameworks-on-the-market

http://deviltechie.wordpress.com/2012/03/29/why-mvc-simply-explained/

Page 22: Why MVC?

Q & A Section

Page 23: Why MVC?

Thank you!

Email : Email : [email protected]

Facebook : Facebook : http://www.facebook.com/waynetunmyint

Linkedin :Linkedin :http://www.linkedin.com/pub/wayne-tun-myintmyint