31
RAD OO Web Maniacs 2008 Peter Bell SystemsForge

RAD OO Web Maniacs 2008 Peter Bell SystemsForge Peter Bell SystemsForge

Embed Size (px)

DESCRIPTION

RAD OO... Patterns - quickly build OO apps Proven (> 50 projects) Collection of tools

Citation preview

Page 1: RAD OO Web Maniacs 2008 Peter Bell SystemsForge Peter Bell SystemsForge

RAD OOWeb Maniacs 2008

Peter BellSystemsForge

Page 2: RAD OO Web Maniacs 2008 Peter Bell SystemsForge Peter Bell SystemsForge

Who Am I?Programmer - 30-40 projects/yr.Researcher - Published academic papers DSM forum/ooPSLAEntrepreneur - Profitable/practicalSystemsForge - 10,000 custom apps/yr.Writer - CFDJ, Fusion Authority QuarterlyPresenter - cf.objective(), CF United, Frameworks, Code Generation 2007, ooPSLA, Domain Specific Modeling Forum, CFCamp . . .

Page 3: RAD OO Web Maniacs 2008 Peter Bell SystemsForge Peter Bell SystemsForge

RAD OO . . . Patterns - quickly build OO apps Proven (> 50 projects) Collection of tools

Page 4: RAD OO Web Maniacs 2008 Peter Bell SystemsForge Peter Bell SystemsForge

RAD OO . . . IS NOT . . .

Standard approach Suitable for all projects Hack job

IS . . . Fast DRY Maintainable

Page 5: RAD OO Web Maniacs 2008 Peter Bell SystemsForge Peter Bell SystemsForge

RAD OO Uses XML Config Base Classes Optional Classes Iterating Business Objects RAD Controller Smart Views RAD Views Custom Data Types

Page 6: RAD OO Web Maniacs 2008 Peter Bell SystemsForge Peter Bell SystemsForge

XML Config<?xml version="1.0" encoding="UTF-8"?><controller>

<title>ProductCatalog</title><name>ProductCatalog</name><defaultAction>viewCategory</defaultAction><actions>

<detail name="viewCategory" object="ProductCategory" method="getByID" PropertyValueList="%Input.CID%" screen="product-catalog-category-detail" />

<detail name="viewProduct" object="Product" method="getByID" PropertyValueList="%Input.PID%" screen="product-catalog-product-detail" />

<display name="displaySearchResults" Data="" screen="product-catalog-search-results" />

</actions></controller>

Page 7: RAD OO Web Maniacs 2008 Peter Bell SystemsForge Peter Bell SystemsForge

XML ConfigProduct extends: BaseObject tableName: tbl_ProductIdentity: ProductID

Properties: Title title required Price money optional default:0 Description WYSIWYG optional

ClassMethods: AdminList: Title,Price OrderBy Title DefaultAdd: Title,Price,Description QuickAdd: Title,Price multiple:5 DefaultEdit: ID, Title,Price,Description

Relationship has-many Category associated optional

Page 8: RAD OO Web Maniacs 2008 Peter Bell SystemsForge Peter Bell SystemsForge

Base Classes

Most code similar Replace code with configuration Samples: BaseService, BaseDAO,

BaseController

Page 9: RAD OO Web Maniacs 2008 Peter Bell SystemsForge Peter Bell SystemsForge

Optional Classes

Only create CFC’s with code All others instantiate base classes

Page 10: RAD OO Web Maniacs 2008 Peter Bell SystemsForge Peter Bell SystemsForge

Lightwire ConfigBusinessObjectList = ApplicationConfig.get("ObjectList");For (i = 1; i lte listlen(BusinessObjectList); i = i + 1) {

// Get current object nameBusinessObjectName = ListGetAt(BusinessObjectList, i);

// Configure Business Object Service ClassesIf (FileExistsinApplication("com.model.#BusinessObjectName#Service")){addSingleton("lb.com.model.#BusinessObjectName#Service");}Else{

If (FileExistsinLibrary("com.model.#BusinessObjectName#Service"))

{addSingleton("lightbase3.library.com.model.#BusinessObjectName#Service");}Else{addSingleton("lightbase3.framework.com.base.BaseService",

"#BusinessObjectName#Service");};};

addConstructorDependency("#BusinessObjectName#Service","#BusinessObjectName#Metadata", "Metadata");

addMixinDependency("#BusinessObjectName#Service","#BusinessObjectName#DAO");addMixinDependency("#BusinessObjectName#Service","DBProvisioner");

};

Page 11: RAD OO Web Maniacs 2008 Peter Bell SystemsForge Peter Bell SystemsForge

Iterating Business Object Encapsulates recordset Handles iteration Generic get/set - can overload Pattern - not implementation E.g. Can drop generic get/set

Page 12: RAD OO Web Maniacs 2008 Peter Bell SystemsForge Peter Bell SystemsForge

Traditional view (initial)<cfoutput query="ProductList">

#ProductID#<br />#Title#<br />#Image#<br />#SKU#<br />#Price#<br />#SalePrice#<br /><br />

</cfoutput>

Page 13: RAD OO Web Maniacs 2008 Peter Bell SystemsForge Peter Bell SystemsForge

Traditional view (after time)<strong>#Title#</strong><br /><cfif len(image)><img src="/ibo/sample/images/#Image#" width="80"><br /><cfelse><img src="/ibo/sample/images/no-image.gif" width="80"><br /></cfif><cfif Len(SKU)>#SKU#<br /></cfif><cfif SalePrice><strong>On sale - only $#Numberformat(SalePrice, "9.99")#<br /></strong><cfelse>Price: $#Numberformat(Price, "9.99")#<br /></cfif>

Page 14: RAD OO Web Maniacs 2008 Peter Bell SystemsForge Peter Bell SystemsForge

Traditional view (not DRY)

Product list (multiple?) Product detail (multiple?) Admin product list Cart display Order display . . . .

Page 15: RAD OO Web Maniacs 2008 Peter Bell SystemsForge Peter Bell SystemsForge

IBO (initial)<cfloop condition="#ProductList.next()#">

#ProductList.display("ProductID")#<br />#ProductList.display("Title")#<br />#ProductList.display("Image")#<br />#ProductList.display("SKU")#<br />#ProductList.display("Price")#<br />#ProductList.display("SalePrice")#<br /<br />

</cfloop>

<cfloop condition="#ProductList.next()#">#ProductList.displayProductID()#<br />#ProductList.displayTitle()#<br />. . .

</cfloop>

OR

Page 16: RAD OO Web Maniacs 2008 Peter Bell SystemsForge Peter Bell SystemsForge

IBO (over time)

<cfloop condition="#ProductList.next()#">#ProductList.displayProductID()#<br />#ProductList.displayTitle()#<br />. . .

</cfloop>

OR

<cfloop condition="#ProductList.next()#">#ProductList.display("ProductID")#<br />#ProductList.display("Title")#<br />#ProductList.display("Image")#<br />#ProductList.display("SKU")#<br />#ProductList.display("Price")#<br />#ProductList.display("SalePrice")#<br /<br />

</cfloop>

Page 17: RAD OO Web Maniacs 2008 Peter Bell SystemsForge Peter Bell SystemsForge

The Concept

Page 18: RAD OO Web Maniacs 2008 Peter Bell SystemsForge Peter Bell SystemsForge

Using the IBOCREATE:<cfscript>

var ProductList = beanFactory.getbean("Product");ProductList.load(GetProducts);

</cfscript>

ITERATE:<cfset ProductList.reset()><cfloop condition="#ProductList.next()#">

#ProductList.get("Title")#<br /></cfloop>

PERFORMANCE:- Single bean - quick to create

Page 19: RAD OO Web Maniacs 2008 Peter Bell SystemsForge Peter Bell SystemsForge

M-V-C

Model: Business logic and persistance

View: Display templates and helpers

Controller: Actions, model calls, selects views

Page 20: RAD OO Web Maniacs 2008 Peter Bell SystemsForge Peter Bell SystemsForge

RAD Controller

Front controller index.cfm?action=<controller>.<method>

Page controller about-us/history.html becomes page.cfm?filepath=about-us/history

Remote controller remote.cfm?object=<object>&

method=<method>&p1=v1&p2=v2& . . .

Page 21: RAD OO Web Maniacs 2008 Peter Bell SystemsForge Peter Bell SystemsForge

Smart Views

View can access model Not true MVC DRYer - for right use cases

Page 22: RAD OO Web Maniacs 2008 Peter Bell SystemsForge Peter Bell SystemsForge

Smart Views Regular Controller:

Data = getProductList() View = product-list.cfm

Smart View: <cfset ProductList = ProductService.getProductList()>

Great for: Ancillary data one off screens

Page 23: RAD OO Web Maniacs 2008 Peter Bell SystemsForge Peter Bell SystemsForge

RAD Model For each business object:

Service a) remote apib) aggregate methodsc) factory

DAO a) All data access (uses data mapper)

Business object Business logic

Page 24: RAD OO Web Maniacs 2008 Peter Bell SystemsForge Peter Bell SystemsForge

RAD View

Site Templates Screen Templates Includes View Helpers (IBOs) Custom Data Types

Page 25: RAD OO Web Maniacs 2008 Peter Bell SystemsForge Peter Bell SystemsForge

Site Templates

Complete HTML page 1..n/project Template chooser

Page 26: RAD OO Web Maniacs 2008 Peter Bell SystemsForge Peter Bell SystemsForge

Screen Templates

Populates content area May have includes/helpers

Page 27: RAD OO Web Maniacs 2008 Peter Bell SystemsForge Peter Bell SystemsForge

View Helpers

CFC methods for simplifying templates

E.g. list paging

Page 28: RAD OO Web Maniacs 2008 Peter Bell SystemsForge Peter Bell SystemsForge

Custom Data Types

Displaying form fields Processing form fields Displaying formatted values

Page 29: RAD OO Web Maniacs 2008 Peter Bell SystemsForge Peter Bell SystemsForge

Custom Data Types

.display() .field() .process()

Page 30: RAD OO Web Maniacs 2008 Peter Bell SystemsForge Peter Bell SystemsForge

Conclusions

Proven in over 50 projects Extremely productive Removes unnecessary flexibility Your milage may vary

Page 31: RAD OO Web Maniacs 2008 Peter Bell SystemsForge Peter Bell SystemsForge

Questions?

Blog: www.pbell.com

Email: [email protected]

Yahoo: freshstartsw

AIM: appgeneration