Tuesday, May 27, 2008

Design Patters - more details

Design Patterns in ColdFusion

Content paraphrased from http://www.jroller.com/page/kwiersma.

I keep coming back to these patterns because I support a large application that implements all of them and have been asked to share my knowledge. This is the knowledge! Granted, there is a lot of business logic in the application, but the architecture of the application follows closely the the principles found in these patterns.

Beans ( Business Objects or Value Objects)
DAOs (Data Access Objects)
Gateways (Data Gateway Objects)
Services (Manager Objects)


The Bean
  • Typically represents a specific entity in your model
  • Carries "encapsulated" data between the different layers of your application
    • like a structure, instead of directly accessing data with a key you call a method
  • Helps organize data structures instead passing structures around ad-hoc
  • Has a consistent and simple interface (Controllable API)
  • Has methods called getters/setters (aka accessors) to access data [getFirstName() / setFirstName()]
  • Might be composed of other beans
  • Easily created with a code generator

DAO (data access object)
  • DAOs only interact with one row of data via the primary key
  • Used to save/load objects from data storage
  • A DAO could interface with: Database / Legacy persistent data storage (XML / Text File)
  • Usually have ScRuD method that take a bean
    • (ScRuD - Save | (create) | Read | (update) | Delete)

Gateways (Aggregated Data)
  • return one or more rows of data
  • Typically returns a cfquery object
  • Rarely it can return a bean (Querying by User/Pwd)
  • Performs functionality that may affect one or more rows
Services: (Kings of the Jungles)
  • Contains your business logic:
  • Bean Validation / Creation
  • Application specific business logic
  • Save / Load / Delete from DAO (via the facade pattern)
  • Gateway Interaction (via the facade pattern)
  • Usually depends on a DAO and Gateway
  • Services can consume other services (very social)

No comments: