Simplify Your Workload

But Not Your Delivery

NCDevCon 2014

By Daria Norris / @cfGothChic

Slide Controls

  • Press right or down to advance slides
  • Press ESC to see the slide overview
  • Hold down alt and click on any element to zoom in on it
  • Alt + click anywhere to zoom back out
  • Press S to see speaker notes

 

reveal.js - The HTML Presentation Framework

Model View Controller

Model

Database Interaction / Business Rules

View

User Interaction

Controller

Traffic Cop

FW/1 && DI/1

Convention not Configuration

index.cfm?action=section.item

  • /controllers
    • section.cfc
      • item()
  • /layouts
  • /model
    • /beans
      • name.cfc
    • /services
      • name.cfc
  • /views
    • /section
      • item.cfm
  • Application.cfc
  • index.cfm

Automatic Controller Calls

index.cfm?action=section.item

  • Application.cfc : before()
  • controllers/section.cfc : before()
  • controllers/section.cfc : item()
  • controllers/section.cfc : after()
  • Application.cfc : after()

 

Views are built after controllers

Layouts are built last

FW/1 3.0

Automatic Bean Factory Usage with DI/1

 

Features Removed

  • Service Queue - service() api function
  • startItem() & endItem()

Application.cfc

 

FW/1 Application Functions

  • setupApplication()
  • setupSession()
  • setupRequest()

 

Use instead of onApplicationStart, onSessionStart & onRequestStart

Framework Setup

 

Potential Options

  • Change default home page
  • Use SES Urls
  • Set password for reloading the application
  • Set options by environment
  • Use a different bean factory than DI/1

RC Structure

Views

Best Practices

 

Use the local scope for variables that only exist for the view

 

Include in other views and layouts with the view() function,
not <cfinclude>

#view("section/item")#

Layouts

Nested Layouts

  • layouts/section/item.cfm – The view-specific layout
  • layouts/section.cfm – The section-specific layout
  • layouts/default.cfm – The site-wide layout

Controllers

"View" Controller

  • Param required url and form variables in rc
  • Get Domain Objects (Beans) from Services
  • Set variables for views
  • Set custom view (optional)
  • Set custom layout (optional)

"Action" Controller

  • Param required url and form variables in rc
  • Get Domain Objects (Beans) from Services
  • Call methods on Beans (& Services) to perform the Actions
  • Set return messages
  • Redirect to new location

Ajax Calls via FW/1

Best Practices

 

Controllers should not call other controllers

 

If you are tempted to break that rule,
maybe your model isn't doing enough

Subsystems

Subsystems

index.cfm?action=subsystem:section.item

  • /admin
    • /controllers
    • /layout
    • /views
  • /common
    • /layout
  • /home
    • /controllers
    • /views
  • /model

DI/1 – Inject Your Services

Automatic Aliasing

 

/model/beans/address.cfc

"addressBean"

 

/model/services/address.cfc

"addressService"

Inject the Model into
Controllers & Services

 

component accessors="true"

 

property {name}Service;

 

variables.{name}Service.method()

Controller Example

Model

There is No
"One True Way"

Using Patterns in Your Model

Typical Object Types

  • Beans
  • Services
  • Data Gateways

Beans

/model/beans/{name}.cfc

  • Where your Business Logic goes
  • Closest relationship to tables in your database
  • Also called Domain Objects

Services

/model/services/{name}.cfc

  • Coordinates tasks between objects
  • Controls the workflow between objects
  • Facilitates communication between objects

Data Gateways

/model/gateways/{name}.cfc

  • Where the SQL lives

 

Also referred to as...

  • Data Access Objects (DAO)
  • Table Data Gateways

Just Use Services

Remember

There is no "Right" way

References

 

Code Examples
Uses FW/1 3.0 & Railo 4.2 or ACF11