ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
Inherited views
When we are using MVC
frameworks only view layer does
not correspond to the OO
principles
What frameworks give us
from the box
? view rendering
? partial rendering
? support of helper methods
Biggest disadvantage of
the view layer
? does not support unit testing
Disadvantages of helpers
? do not allow inheritance
? methods are calling without a receiver
? collision between helpers with similar methods
We can replace helpers to
decorators and improve
presentation logic
Advantages of decorators
? allow inheritance
? allow encapsulation
? friendly for unit testing
? does not mutate decorated object
? does not change the behavior of decorated object
Decorators has
advantages over helpers
But decorators are not
developed for view layer
View Components
next generation of view layer
Cells
view-model layer
Advantages of ¡®cells¡¯
? basically a small MVC stack
? own render engine
? OOP features
? separate presentation from the view logic
Bene?ts for application
structure
? slim controllers
? clear views
? maintainability
When do we need
such approach?
Cells applicable for
? layouts
? generic views
? complex view logic
? widgets
Simple example
Typical situation
? duplicated views for some UI
part
? each view can render speci?c
partials
? each partial can build speci?c
content
Every new case expects
change of current condition
state and ?le structure
Somebody should
maintain this stuff
To avoid this painful we
can use the power of
components
De?ning base logic
De?ning base partials
Inheriting our component
Customizing our partials
Calling our component
Inherited views
Conclusions
? separated from presentation logic
? easy maintenance
? test coverage
? isolated dependencies
¨CValentyn Ostakh
Thanks!
Questions?

More Related Content

Inherited views