140 likes | 278 Views
Model-View-Controller in Web Applications. Jan Tvrdík. Model- V iew - C ontroller. MVC software architecture model – business logic view – what the user sees controller – responds to user events . History. lots of slightly different implementations Trygve Reenskaug
E N D
Model-View-Controllerin Web Applications Jan Tvrdík
Model-View-Controller • MVC • software architecture • model – business logic • view – what the user sees • controller – responds to user events
History • lots of slightly different implementations • TrygveReenskaug • 1st draft released in the May 1979 • Model-View-Editor • 2nd draft released in the December 1979 • Models-Views-Controllers
The First Implementation • Model-View-Controller as known today • Written in Smalltalk in 1987 • Considered to be the “Classic MVC“
MVC Diagram Controller Model View
Model • Data + business logic • Meaning of data • Behavior of application • Communication with database • Calculations • Not aware of view / controller existence
View • Visual representation of its model • May highlight or suppress certain attributes of the model • Active = directly communicates with model • Passive = communicatesonly with controller
Controller • Glue between model and view • Processes the user request • Changes the model • Redraws the view • More complicated in web apps
Front Controller • Processes the HTTP request • Picks a specific controller
Front Controller Model Front Controller Controller Controller Controller View View View Request
Useful guidelines • If you change the name of column in database, you shouldn’t need to edit the code of view and controller. • If you change the HTML output to Flash, you shouldn’t need to edit model’s code. • If you change the position of certain elements on page, you shouldn’t need to edit the code of controller and model.
Advantages • Improvescodeorganization • Codetestability • Codereuse • Extensibility • Adapted by most web frameworks
Disadvantages • Increasedcodecomplexity • MVC paradoxes
Conclusion • MVC has no exact definition • Start using MVC today! • Find a good framework