Domain-Driven JavaScript Development

Preview:

DESCRIPTION

We are building more and more complex applications on the front-end of the web stack. We've done a good job of bringing engineering rigor to JavaScript development, but we can do more. We need overall architectural design for our complex applications. Domain-Driven Design offers us a way of approaching software design on the front-end. We walk through the process of setting up a small domain-driven application in Backbone.js.

Citation preview

http://www.flickr.com/photos/lac-bac/4678565737/http://www.flickr.com/photos/lac-bac/4678565737/

Bob HoltSpecialist, Interactive Development

Sapient Global MarketsVisualization Practice

@bobholtgithub.com/bobholt

• Asset Management

• Design Patterns

• Modularization

• Linting

• Testing

• Build Process

http://www.flickr.com/photos/sidelong/6433552779/http://www.flickr.com/photos/sidelong/6433552779/

http://en.wikipedia.org/wiki/File:Joy_Oil_gas_station_blueprints.jpghttp://en.wikipedia.org/wiki/File:Joy_Oil_gas_station_blueprints.jpg

Domain

The subject of the program

Examples:

•Airline booking program: People getting on aircraft

•Stock Trading program: Securities and exchanges

Domain-Driven Design

Manage complex software by placing primary focus on the domain.

•Principles•Techniques•Practices

What if my software isn’t complex?

“Put all the business logic into the user interface. […] Use the most automated UI building and visual programming tools available.”

-Eric Evans

http:

//w

ww

.flic

kr.c

om/p

hoto

s/si

nam

igos

/750

9698

756/

Domain-Driven Design

Manage complex software by placing primary focus on the domain.

•Principles•Techniques•Practices

Domain Model

• Abstraction of the knowledge in a domain expert’s head

• Intimately linked with the software implementation

• If a domain model cannot be understood by sophisticated domain experts, then there is something wrong with the model.

Building a Domain-Driven Application

https://github.com/archfirst/bullsfirst-jquery-backbone

https://github.com/archfirst/bullsfirst-jquery-backbone

The FrameworkBuilding a Domain-Driven Application

Backbone.js

In an ecosystem where overarching, decides-everything-for-you frameworks are commonplace, and many libraries require your site to be restructured to suit their look, feel, and default behavior — Backbone should continue to be a tool that gives you the freedom to design the full experience of your web application.

- Jeremy Ashkenas

Keel

• Lightweight framework around Backbone.js

• About patterns and practices, not fancy code

• 5 Files: BaseView, ExceptionUtil, Message, MessageBus, Router

https://github.com/archfirst/keel

Pattern

• Component– View – Template– ViewModel

https://commons.wikimedia.org/wiki/File:Russian-Matroshka_no_bg.jpghttps://commons.wikimedia.org/wiki/File:Russian-Matroshka_no_bg.jpg

The ProcessBuilding a Domain-Driven Application

Discovery

• Begin constructing the domain model

• Develop an ubiquitous language

Ubiquitous Language

• Concept shared with Behavior-Driven Development

• Defined terminology that is shared between all members of the team

• Used in all code and written and verbal communication

Building the domain model and ubiquitous language is an iterative process

Isolate the Domain

Express the Model in Software

• Distinguish Entities, Value Objects, and Services

• Set Aggregate Boundaries

• Implement Repositories and Factories

Set Aggregate Boundaries

Positions

Transactions

Orders

Lots

Brokerage Account

Repositories

• Global interface

• Provides illusion of in-memory collection of all objects

• Deals with the data store

• Caches as necessary

Factories

• Take on the responsibility of creating new objects

• Tying to domain or application can be ungainly

• However, Backbone has Collection.add and Model.validate methods that can take care of this for us

http:

//co

mm

ons.

wik

imed

ia.o

rg/w

iki/

File

:Dee

p_in

_tho

ught

.jpg

Resources

• Domain-Driven Design– Domain-Driven Design: Tackling Complexity in the

Heart of Software – Eric Evans– Domain Driven Design Quickly – InfoQ– Domain-Driven Design – Nettuts+

• Keel.js– Keel – GitHub– Bullsfirst – GitHub– Archfirst Project