1 / 16

Model View Controllers (MVC)

Model View Controllers (MVC). Barack Karavani. Outline. What is MVC? Why use the MVC Pattern? MVC and the Web Benefits of MVC in Web Applications Modern MVC Frameworks. What is MVC. MVC is a pattern Patterns are commonality that we find amongst software

lajos
Download Presentation

Model View Controllers (MVC)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Model View Controllers (MVC) Barack Karavani

  2. Outline • What is MVC? • Why use the MVC Pattern? • MVC and the Web • Benefits of MVC in Web Applications • Modern MVC Frameworks

  3. What is MVC • MVC is a pattern • Patterns are commonality that we find amongst software • Architectural Pattern - Provide solutions to various issues in Software Engineering • Design Patterns - Provide solutions to repeated issues in Software Development • MVC solves common issues by separating important parts into three subsystems.

  4. Why MVC • Decouple the interaction between user interfaces and data stores. • Provide a clear separation of concern between components. • Promote the development of reusable components.

  5. MVC and the Web Model View Controller

  6. Benefits of MVC in Web Applications • Websites and Web Applications are great candidates for the MVC Pattern. • Inherently clear distinction for models, views, and controllers. • Multiple frameworks exist in various languages which support and encourage the MVC Pattern and other great coding principles!

  7. Popular MVC Web Frameworks • Open Source frameworks are actively being developed • Promote the MVC Pattern • Definitions of MVC may change depending on the framework philosophy, READ THE DOCS!

  8. Popular MVC Web Frameworks • MVC Frameworks exist both on the client-side and server-side Client Side (JS): • Backbone • AngularJS • EmberJS Server Side: • Django (Python) • Laravel (PHP) • Rails (Ruby)

  9. Benefits of MVC in Web Applications • By promoting the use of reusable components, we prevent ourselves from writing “spaghetti” code. • Spaghetti Code - One-off code which interleaves business logic (model/controller) with view responsibilities • Hard to maintain • Hard to read • Does not scale well • Provide commonly used tools to web developers

  10. Example of Spaghetti Code <? if(($child_assent || $adol_assent) && $form['short_name'] == 'parental_consent' && $canEdit): ?> <div class="form-helpers"> <? else: ?> <div class="form-helpers hide"> <? endif; ?>

  11. Common Tools • Active Record and Object Relational Mapping (ORM) • Routes • Templating • Form and Input Validation • Security and Authentication • Testing & Test Cases

  12. Views in Laravel, Django, Rails • Typically views for web applications consist of the HTML/CSS/JS side of things • Do not interact directly with the model • All three frameworks implement their version of a templating system. • Contain either simple logic or none at all • Prevents spaghetti code (by not allowing ANY code) • Promotes developing small templates to be reused and combined in multiple places

  13. Templating {% if latest_poll_list %} <ul> {% for poll in latest_poll_list %} <li>{{ poll.question }}</li> {% endfor %} </ul> {% else %} <p>No polls are available.</p> {% endif %} <% @books.each do |book| %> <tr> <td><%= book.title %></td> <td><%= book.content %></td> </tr> <% end %> Django Rails

  14. Models in Laravel, Django, Rails • Models are defined as objects. • Instances of models represent rows within the database table. • Frameworks will automatically build database tables based upon models. • Controller can interact with the models as native language objects.

  15. Controllers in Laravel, Django, Rails • Controllers are functions that are called when a user accesses certain pages. • One controller can be called for multiple URLs. • Processes input data from the user. • Returns data to be styled in the view for the user to interpret.

  16. Questions?

More Related