What is MVC?3:10 with Chris Ramacciotti
You've been practicing the Model-View-Controller architectural pattern throughout this course, even if you weren't aware. In this video, I'll explain exactly what MVC is, and how it helps us organize our application code.
[MUSIC] 0:00 If you've made it this far into your study of Java, 0:04 you know that Java and programming in general is full of acronyms, 0:09 jdk, jre, jvm, jar, oo, ide, dry, di. 0:15 POJO, and the list goes on and on, but 0:21 there is one acronym I've used in this course that is integral to the development 0:26 of our application, and I haven't explained it yet. 0:30 It's MVC. 0:33 MVC stands for model view controller and 0:35 it's a software design pattern we've already used in Giflib. 0:38 In this setup, we categorized our components which are really just classes 0:42 as models, views, and controllers. 0:46 The point of this design pattern or 0:49 architecture is to separate the logical components of an application so 0:51 that each component performs very specific and limited tasks. 0:55 In computer science, 1:00 this idea of separation is called the separation of concerns. 1:01 In an MVC app, 1:06 the model's job is to store the underlying data, in our case, all the gift details. 1:08 A controller's job is to process user actions, fetching and 1:14 altering the underlying model data as needed. 1:18 Then providing that model data to associated views. 1:20 The Views job is to present model data to users and 1:24 expose a user interface for interacting with the data. 1:27 Such as clickable links, form fields and buttons. 1:31 In our application, a gift object is our only model, 1:35 Time leaf templates are the views, and the gif controller is our only controller. 1:38 So it turns out you've been using MVC all along, even if you didn't know it. 1:43 This MVC pattern is leveraged by many web frameworks in various languages. 1:48 Some examples are the ASP.NET MVC framework in C#, the Laravel framework in 1:53 php, the Rails framework in Ruby, the Django framework in Python, 1:59 though they might call it MTV for model template view instead of MVC. 2:04 Same idea though. 2:09 Or, hey, this Spring framework in Java. 2:11 To wrap up our spring basics course, I'd like to reinforce the MVC design principle 2:15 by writing one more model, a couple more views, and one more controller. 2:20 Though, we have various options here. 2:25 Since we have a link for 2:27 categories that's completely untouched and non-functional, let's focus on that. 2:28 During this stage, I'm going to ask a bit more of you upfront. 2:34 I'm going to assign you big tasks such as code a category model or 2:38 write two time leaf templates, then set you loose. 2:43 Don't worry though. 2:47 After pausing and coding your solution, simply continue watching and 2:48 I'll show you how I went about solving the same problem. 2:52 Try your best to come up with your own solution before reviewing mine. 2:56 You'll have way more satisfaction with this approach and it won't feel so 3:00 much like a typing exercise. 3:04 Let's give it a shot in the next video after a quick check for understanding. 3:06
You need to sign up for Treehouse in order to download course files.Sign up