26
DDD and Beyond … on Rails!!

DDD and Beyond … on Rails! !

  • Upload
    adele

  • View
    53

  • Download
    5

Embed Size (px)

DESCRIPTION

DDD and Beyond … on Rails! !. Why Rails?. Ruby is awesome! Vibrant community & ecosystem CoC - less boilerplate code Supports rapid development Asset pipeline Built-in ORM – ActiveRecord And more …. Why DDD?. Powerful practices & patterns for tackling complex problems - PowerPoint PPT Presentation

Citation preview

Page 1: DDD  and Beyond …  on Rails! !

DDD and Beyond … on Rails!!

Page 2: DDD  and Beyond …  on Rails! !

Why Rails?

• Ruby is awesome!• Vibrant community & ecosystem• CoC - less boilerplate code• Supports rapid development• Asset pipeline• Built-in ORM – ActiveRecord• And more …

Page 3: DDD  and Beyond …  on Rails! !

Why DDD?• Powerful practices & patterns for tackling complex problems

– Both tactical and strategic• Align business & technology

– Zero translations (Ubiquitous Language)– Domain experts contribute to software design– Code becomes a living description of the business

• Increased clarity and understanding– Collaboration that results in well understood models

• Strategic development– Prioritize resources & investment toward more complex or differentiating

areas of the business• Organized architecture

– Align physical systems with distinct areas of the business

Page 4: DDD  and Beyond …  on Rails! !

DDD on Rails

Rails• Ruby is awesome!• Vibrant community• Less boilerplate• Rapid development• Asset pipeline• ActiveRecord

DDD• Tackle complex domains• Align business & technology• Clarity & understanding• Strategic development• Organized Architecture

* ActiveRecord is a DDD antipattern ….

Page 5: DDD  and Beyond …  on Rails! !
Page 6: DDD  and Beyond …  on Rails! !
Page 7: DDD  and Beyond …  on Rails! !

DDD: Strategic Patterns

SubdomainsUbiquitous Language

Bounded Context

• Separate areas of the business• Ideally one Domain Model per Subdomain

• Language used & understood by all stakeholders in a project • Used to express a Domain Model

• Sets the context for terms in a Ubiquitous Language• Ideally one Bounded Context per Subdomain

Page 8: DDD  and Beyond …  on Rails! !

Conference Management

Page 9: DDD  and Beyond …  on Rails! !

Subdomains

Page 10: DDD  and Beyond …  on Rails! !

Ubiquitous Language

• Program Mgmt. Context– Organizers create Conferences– Organizers call for Proposals– Candidates submit Proposals– Once received, Reviewers rate Proposals– Organizers choose Proposals for Session topics

• Access Control Context– Public Users register to create an Account– Accounts are assigned to one or more Roles– Users sign in to begin an authenticated Session

Page 11: DDD  and Beyond …  on Rails! !

User Story:As a candidateI would like to submit a proposal to a conferenceSo that it may be available for review

Ubiquitous Language

Page 12: DDD  and Beyond …  on Rails! !

Isolating Contexts

Gem, Engine, App

Gem, Engine, App

Page 13: DDD  and Beyond …  on Rails! !

Anticorruption Layer

Page 14: DDD  and Beyond …  on Rails! !

DDD: Tactical Patterns

• Entity• Aggregate• Repository• Value Object• Domain Event• Domain Service

* Building blocks of a Domain Model

Page 15: DDD  and Beyond …  on Rails! !

ActiveRecord – Schema First

Page 16: DDD  and Beyond …  on Rails! !

DDD – Model First

Page 17: DDD  and Beyond …  on Rails! !

ActiveRecord

DDD Entity

Organizer creates a conference.

Page 18: DDD  and Beyond …  on Rails! !

ActiveRecord

DDD Entity

Organizer calls for proposals.

Page 19: DDD  and Beyond …  on Rails! !

ActiveRecord

DDD Entity

Candidate creates and submits a proposal.

Page 20: DDD  and Beyond …  on Rails! !

ActiveRecord

Proposals can only be received once the organizer has called for proposals.

Page 21: DDD  and Beyond …  on Rails! !

DDD Entity

Proposals can only be received once the organizer has called for proposals.

Page 22: DDD  and Beyond …  on Rails! !

ActiveRecord vs DDD Entity

ActiveRecord• Shaped by DB schema• CRUD semantics baked in• No Encapsulation• Multiple responsibilities

– Data access– Business logic– REST resource/view data

DDD Entity• Shaped by UL• Blank canvas to express UL• Enforces invariants• Single responsibility

– Encapsulate business logic

Page 23: DDD  and Beyond …  on Rails! !

Repositories

• Collection semantics for an Aggregate Root– add(conference), find_by(id) etc.

• Modify one Aggregate per transaction *– Consistency boundary– Watch out for false invariants

• Easily implemented with NoSQL solutions– Object/Document/Key-values etc.

Page 24: DDD  and Beyond …  on Rails! !

Event Sourcing

• Raise explicit event for every state change• Persist serialized events to an event store

• To retrieve persisted entity– Deserialize events and replay– Conference.allocate.replay(events)

Event Name Source Id Event Args

conference_created 7 { id: 12, name: “Test Conf” }

conference_scheduled 7 { id: 12, date: “2013-31-01”}

proposal_received 7 { id: 12, title: “Test Prop …

Page 25: DDD  and Beyond …  on Rails! !

Event Sourcing & CQRS

Client

Application

Domain Model

Commands Queries

Query Store

Application

Read-only

AsyncHandlers

DB

Events