22.08.2015 Views

ColdBox? Mach-II? Model-Glue?

Frameworks (PDF) - An Architect's View

Frameworks (PDF) - An Architect's View

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>ColdBox</strong>? <strong>Mach</strong>-<strong>II</strong>?<strong>Model</strong>-<strong>Glue</strong>?Sean CorfieldRailo Technologies, Inc.1


Structure offrameworks4


Traditional Applications• Display code• Link to page / form submit to page• Validation / data processing in page or adhoc includes / CFCs• Logic to select next page5


Traditional Applications• • ... process data ...• ... redirect or continue to show errors ...• • • ...• 6


<strong>Model</strong>-View-Controller• View = display code• Controller = logic to select next page, formvalidation, interaction with <strong>Model</strong>• <strong>Model</strong> = all the business logic - validation,data processing etc7


<strong>Model</strong>-View-Controller• All requests go through the Controller• It writes to the <strong>Model</strong> and reads data backfrom the <strong>Model</strong>• It selects the View to render• Views may read from the <strong>Model</strong> (or dataprovided by the Controller)8


Types of framework• MVC - application frameworks• cfWheels, <strong>ColdBox</strong>, Fusebox, <strong>Mach</strong>-<strong>II</strong>,<strong>Model</strong>-<strong>Glue</strong>, onTap etc• ORM - persistence frameworks• DataFaucet, Hibernate (Java), Reactor,Transfer etc9


Types of framework• IoC / DI - management of services (CFCs)• ColdSpring, Lightwire, Spring (Java)• Miscellaneous• Validation frameworks• Event handling frameworks• etc10


What do they all havein common?11


Commonalities• What do <strong>ColdBox</strong>, <strong>Mach</strong>-<strong>II</strong> and <strong>Model</strong>-<strong>Glue</strong>have in common?• More than you might think!12


Commonalities• index.cfm - entry point for Controller (theframework plus your CFCs together)• event-based - focused on "handlers"• event "object"• Contains URL and form data• Provides a data bus for Controller / View13


Commonalities• URL and form scope are blended together• Views are "regular" CFML pages• Controllers are CFCs• <strong>Model</strong> is a collection of CFCs too14


Configuration vsConvention• Event handlers are specified in XML files• <strong>Mach</strong>-<strong>II</strong>, <strong>Model</strong>-<strong>Glue</strong> - like Fusebox XML• Event handlers are located by convention• <strong>ColdBox</strong> - like Fusebox no-XML15


How are they different?16


<strong>ColdBox</strong>17


<strong>ColdBox</strong>• Event names look like entity.action• Map to handler entity.cfc, method action(event) - like Fusebox no-XML• Default view would be entity/action.cfm• Handler can set a different view• e.g., user.list -> user.cfc:list() -> user/list.cfm18


<strong>ColdBox</strong>• Core configuration is via XML file• Just basic properties - no "logic"• Layouts• Default layout for whole app• Default layout for specific views/folders• Can override programmatically19


<strong>ColdBox</strong>• Interceptors - called automatically duringthe application / request lifecycle• SES URLs, security, tracing, cache advice...• e.g., environment interceptor canoverride configuration for dev, QA, prod20


<strong>ColdBox</strong>• Plugins - add custom functionality• Create plugins/Stuff.cfc• In view or handler, getMyPlugin("Stuff")• Automatically cached• Lots built-in: i18n, logger, RSS, webservices, timer etc21


<strong>ColdBox</strong>• Incredible documentation!• It's a very rich framework with a lot offunctionality but it's also very easy to getstarted• I find it a bit verbose and I think somesimple things are harder - sometimes muchharder - than they need to be...22


<strong>Mach</strong>-<strong>II</strong>23


<strong>Mach</strong>-<strong>II</strong>• Event handlers in XML• Call methods on listener CFCs• Specify views to render• Can publish message for subscribedlisteners• Can map event names• Both decouple listeners from XML24


<strong>Mach</strong>-<strong>II</strong>• XML also defines• Modules - to decompose large apps• Subroutines - reusable handler "logic"• Properties - simple and complex• e.g., ColdspringProperty CFC• Can be like plugins in <strong>ColdBox</strong>25


<strong>Mach</strong>-<strong>II</strong>• Plugins - a bit like interceptors in <strong>ColdBox</strong>• Automatically called during each request• Filters - conditional logic for event handlers• Can change flow of events• Built-in caching, logging (as of 1.6)26


<strong>Mach</strong>-<strong>II</strong>• Environment support (as of 1.8)• Conditional configuration based on dev,QA, prod server groups• HTML helper (as of 1.8)• Reduces clutter in views by encapsulatingboilerplate code and common operations27


<strong>Mach</strong>-<strong>II</strong>• Reasonable documentation• Strong, consistent architecture• Very "OO" which can be a barrier for some28


<strong>Model</strong>-<strong>Glue</strong>29


<strong>Model</strong>-<strong>Glue</strong>• Event handlers in XML• Publish messages for subscribed listeners• Specify conditional result / event mapping• Specify views to render30


<strong>Model</strong>-<strong>Glue</strong>• Controller CFCs (methods are listeners)• Conditional logic sets "results" to controlthe flow of events (like filters in <strong>Mach</strong>-<strong>II</strong>)• A few automatic events during eachrequest (like plugins in <strong>Mach</strong>-<strong>II</strong> orinterceptors in <strong>ColdBox</strong>)31


<strong>Model</strong>-<strong>Glue</strong>• Scaffolding (MG2) / code generation (MG3)• Builds XML, controllers and views for youto speed up development• Event types (new in MG3)• Reduces boilerplate layout / resultmapping in event handler XML32


<strong>Model</strong>-<strong>Glue</strong>• Integrated ColdSpring• Autowiring of model into controllers• <strong>Model</strong>-<strong>Glue</strong> itself is wired together withColdSpring!33


<strong>Model</strong>-<strong>Glue</strong>• View formats (new in MG3)• Select different views in single eventhandler to render HTML or XML or ...34


<strong>Model</strong>-<strong>Glue</strong>• Very simple, clean architecture• Aimed at CFers (even tho' it is OO)• Documentation is steadily improving andthere is now self-paced online training35


Show & Tell!36


Let's see some code!• I'm going to install each framework andthen we can have a look at a small sampleapplication with each one37


Wrap up...• At a high level, <strong>ColdBox</strong>, <strong>Mach</strong>-<strong>II</strong> and<strong>Model</strong>-<strong>Glue</strong> perform similar functions• <strong>ColdBox</strong> has convention-based approach• <strong>Model</strong>-<strong>Glue</strong> is lightweight and simple• <strong>Mach</strong>-<strong>II</strong> is very OO and built for extension38


Q&A• sean@corfield.org• sean@getrailo.com• http://corfield.org/• http://getrailo.com/39

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!