Feed Your Beans

From Anemic to Domain Driven Modeling


dev.Objective() 2015

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

MVC, Now What?

Object

Oriented

Using Patterns in Your Model

OOP Languages

  • CFML
  • Groovy
  • JavaScript
  • PHP 5.6+
  • Python 3+
  • Ruby on Rails
  • ...

Typical Object Types

  • Services
  • Beans
  • Data Gateways

Services

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

Beans

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

Data Gateways

  • Where the SQL lives

 

Also referred to as...

  • Data Access Objects (DAO)
  • Table Data Gateways

Four Layer Cake

Business Logic vs Database Access

Recipe Overview

1 2
3 4

Recipe #1

Recipe #2

Recipe #3

Recipe #4

1 2
3 4

Recipe #1

Beware of
5:1 Syndrome

  • userBean
  • userController
  • userDAO
  • userGateway
  • userService

Recipe #4

Object Think

Recipe #3

Active Record

 

Encapsulates all code related to a single table record

 

Includes both SQL and Business Logic

Recipe #2

Best Option

#1 - 5:1 Syndrome
#2 - Best Option
#3 - Active Record
#4 - Object Think

Domain Objects

Eating Well
or Poor Diet?

To ORM or Not To ORM

Anemic Data Model

 

Beans end up being "just data"

 

Result of the 5:1 Syndrome

 

ORM applications tend to suffer from this

Data Mapper

Feed Your Beans

References