Slide 1

Slide 1 text

Hierarchical MVC What, Why, and How Vance Lucas (@vlucas) Friday, March 2, 2012

Slide 2

Slide 2 text

Who am I? • Vance Lucas • http://vancelucas.com • @vlucas • Business: http://brightb.it • Oklahoma City • Web developer since 1999 (PHP3) • PHP, JavaScript, Ruby / Web & Mobile Friday, March 2, 2012

Slide 3

Slide 3 text

What is HMVC? Friday, March 2, 2012

Slide 4

Slide 4 text

Multiple MVC triads working together to compose a single HTTP Response for a single HTTP Request Friday, March 2, 2012

Slide 5

Slide 5 text

Multiple MVC Triads, Single Response http://techportal.ibuildings.com/2010/02/22/scaling-web-applications-with-hmvc/ Friday, March 2, 2012

Slide 6

Slide 6 text

Properties of HMVC • Many MVC triads working together • Separation of responsibilities of display • Modularization of content & display types Friday, March 2, 2012

Slide 7

Slide 7 text

HMVC is the “widgetization” and modularization of content Friday, March 2, 2012

Slide 8

Slide 8 text

Modular MVC Triads Friday, March 2, 2012

Slide 9

Slide 9 text

A quick note on HMVC... Friday, March 2, 2012

Slide 10

Slide 10 text

Most HMVC implementations are not actually Hierarchical Friday, March 2, 2012

Slide 11

Slide 11 text

A more useful term might be Nested MVC when no hierarchy is tracked or enforced Friday, March 2, 2012

Slide 12

Slide 12 text

Why HMVC? Friday, March 2, 2012

Slide 13

Slide 13 text

HMVC design promotes broader code re-use and separation of responsibilities though natural organization and dispatching of MVC triads Friday, March 2, 2012

Slide 14

Slide 14 text

Instead of using partials and shared template fragments, just pass the responsibility to another MVC triad Friday, March 2, 2012

Slide 15

Slide 15 text

should know how to render Friday, March 2, 2012

Slide 16

Slide 16 text

Benefits of HMVC • Shift the responsibility of the display and logic down to a self-contained MVC structure • Eliminate repetitive code in controllers passing data to templates and templates passing data to and rendering partials • Call directly in view where needed for display • Built-in widget-like structures • Keep extra business logic contained inside module that deals with it Friday, March 2, 2012

Slide 17

Slide 17 text

How do I use HMVC? Friday, March 2, 2012

Slide 18

Slide 18 text

Anywhere you would use a widget or related but separate content type on a page Friday, March 2, 2012

Slide 19

Slide 19 text

Any Shared Content Type • Comments • Tags / Tag Clouds • Ratings • Shopping Cart Contents • Menus • RSS/Blog Feeds • Calendars • (etc...) Friday, March 2, 2012

Slide 20

Slide 20 text

How about some Code? Friday, March 2, 2012

Slide 21

Slide 21 text

Modular MVC Triads Friday, March 2, 2012

Slide 22

Slide 22 text

Alloy HMVC Example Friday, March 2, 2012

Slide 23

Slide 23 text

Kohana 3.0 HMVC Example Friday, March 2, 2012

Slide 24

Slide 24 text

Symfony 2 HMVC Example Friday, March 2, 2012

Slide 25

Slide 25 text

Demo Code! Friday, March 2, 2012

Slide 26

Slide 26 text

[email protected] http://brightb.it (405) 595-0011 Oklahoma City Friday, March 2, 2012