crafted design - ljc world tour mash up 2014
DESCRIPTION
New version of the Crafted Design talk.TRANSCRIPT
![Page 1: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/1.jpg)
crafted designsandromancuso
an introduction to Interaction-Driven Design (IDD)
![Page 2: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/2.jpg)
What is this application about? What are the main concepts?
What does it do? What are the main features?
Where do I change it? Where do I add a new feature or fix a bug?
![Page 3: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/3.jpg)
Badly structured packages/namespaces
Architectural and design concepts mixed with domain
Classes and methods are too low level
Acceptance tests either absent or badly written
![Page 4: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/4.jpg)
Example: Layered structure
![Page 5: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/5.jpg)
Example: Layered-domain structure
![Page 6: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/6.jpg)
Example: MVC structure
![Page 7: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/7.jpg)
![Page 8: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/8.jpg)
MVC & MVC Variations
• MVC (Smalltalk 76/80)
• MVC (general concept – 1988)
• Three-Tier Architecture (Presentation, Logic,
Data)
• MVC (Model 1/Model 2)
• Model View Adapter (MVA)
• Model View Presenter (MVP)
• Model View ViewModel (MVVM)
• Presentation-Abstraction-Control (PAC)
• ….
![Page 9: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/9.jpg)
Views impact MVC structure
Depending on the view technology, Views and Controllers
responsibility becomes more/less coupled or blurred.
Traditional multi-page web applications
Single-page AJAX applications with stateless backend
Console-based applications
Desktop applications
Games
Mobile / tablets
External systems (talking via Queues / Webservices)
However, the model should remain unchanged.
![Page 10: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/10.jpg)
MVC used badly
AnaemicDomain
Fat Controllers
Coupling with MVC framework
![Page 11: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/11.jpg)
MVC – A Macro Organisational Pattern
Model
V C M
Delivery
Mechanism
![Page 12: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/12.jpg)
“Model” is overloaded and
confusing
Model (M in MVC)
Domain Model (DDD)
View Model
Data Model
Entities & Active Record
and other artificial definitions from MVC frameworks
Associated with the persistence mechanism?
![Page 13: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/13.jpg)
M => Domain Model (DDD)
Domain Model combines state and behaviour,
with more focus on the latter.
DDD define a few building blocks to your domain:
Entities
Value Objects
Factories
Repositories
Services Application
Domain
Infrastructure
Aggregates
![Page 14: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/14.jpg)
View, Controller, Domain Model
ModelV C DM
Delivery
Mechanism
DB
Queue
![Page 15: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/15.jpg)
<< Web app >>
Embedded Domain Model
ModelV C DM
Delivery
Mechanism
Infrastructure Infrastructure
DB
Queue
![Page 16: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/16.jpg)
Deployable Domain Model
Delivery
Mechanisms
<< external system >>
<< mobile app >>
DB
<< deployable app >>
Model
Infrastructure
DM<<W/S>>
<<W/S>>
![Page 17: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/17.jpg)
Event-Driven Domain Model
Delivery
Mechanisms DB
Queue
<< external app 2 >>
<< external app 1 >> << deployable app >>
Model
Infrastructure
DMQueue
<<event 1>>
<<event 2>>
![Page 18: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/18.jpg)
Domain Model building blocks & responsibilities
A = Action, DS = Domain Service, S = Infra. Service, R = Repository
Model
A 1
R 3
DS 1
DS 3
R 1
S
Infrastructure Impl
DM
DS 2
Impl
A 2
<< web app >>
![Page 19: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/19.jpg)
Behaviour: Action, Domain Service or Entity?
Domain
Service
Entity
ActionDefines the action that our domain model must
execute.
Behaviour related to multiple instances of the same entity
or different entities.
Behaviour that doesn’t fit any specific entity.
Behaviour related to the data contained in a single
entity instance
![Page 20: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/20.jpg)
Repositories (not DAOs)
Model
<<repository>>
Library
<<repository>>
Users
Infrastructure<<Mongo>>
Books
Domain Model
<<Oracle>>
Users
“A Repository represents all objects of a certain type as a conceptual set. It acts
like a collection, except with more elaborate querying capability.”
~ Eric Evans
![Page 21: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/21.jpg)
An example would be good…
Order
History Orders
<<interface>>
Card Processor
Payment
ValidatorMake
Payment
User Account
CheckerUsers
valid account?
Payment
Gatewaypay
has prime account?
process card
validate
store order
Action Domain Service Infra. Service Repository Class
<<interface>>
Email Sender
email confirmation
![Page 22: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/22.jpg)
Class responsibility
C A DS R
cl
Input Output
End of code branch
Produces the output
End of flow
First to handle input
Start of the flow
Execution Flow
Closer to the input: Control flow, higher level abstraction, detailed work is delegated
(e.g. ProcessTrade (A), MakePayment (A)) — More suitable for Outside-In TDD
(mockist).
Closer to the output / end of branch: Specific and detailed behaviour, no delegation,
lower level abstraction (e.g. Parse XML (Parser), Create User (Repository))
Domain Model entry
point Domain Concept
entry point
![Page 23: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/23.jpg)
Domain Model collaborations guideline
C1
A 1
A 2
DS 1
DS 4
DS 3
R 4
R 1
cl
cl
cl
cl
C = Controller, A = Action, DS = Domain Service, R = Repository, cl = class
DS 2X
A 3 R 5XC2 Except for read model
X
![Page 24: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/24.jpg)
Command & Query Actions
<< web app >>
Model
RDS
<<Write Model>>
A
Model
<<Read Model>>
A R
DB
DB
Queue <<domain events>>
![Page 25: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/25.jpg)
So, how does the app structure look like?
![Page 26: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/26.jpg)
Web project responsibility
Control flow (invoke actions)
JSON / XML parsers or converters
View Models, validators, etc
Static files
Delivery Mechanism: Defines the user journey
![Page 27: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/27.jpg)
Core responsibility (simple project)
Tells what the system is about
Tells what the system does
![Page 28: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/28.jpg)
Core responsibility (bigger project)
Epic / Theme
Epic / Theme
Epic / Theme
Related domain concepts
![Page 29: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/29.jpg)
What is inside model packages?
Aggregate root (entity)
Repository
Entity (part of Book aggregate)
Domain Service
Value Object (part of Book aggregate)
Part of aggregate behaviour
Repository
Value Object (part of User aggregate)
Aggregate root (entity)
Domain Service
![Page 30: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/30.jpg)
What is inside infrastructure?
Interfaces defined by the domain.
Dependency Inversion Principle (DIP)
CreditCardProcessor implementations
Repository implementations
![Page 31: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/31.jpg)
Interaction-Driven Design – IDD(Outside-In design)
C A DS R
cl
Input Output
Execution Flow
Starting from the action, model the expected behaviour (outside-in)
Entities (data structures) will emerge in order to satisfy the behaviour
Focus is on the behaviour of the system and not on how data is stored/related
Design Flow
![Page 32: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/32.jpg)
DB
HTML
JSON
1 Horizontal
+
‘N’ Vertical slices
Feature
![Page 33: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/33.jpg)
DB
![Page 34: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/34.jpg)
Defining testing strategies and boundaries
• Unit
• Integration
• Acceptance
• Journey
• Black box
• Component
• System
• Functional
• Alpha
• Beta
• Conformance
• …
Types of tests
![Page 35: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/35.jpg)
Testing strategies: User Journey
Model
A 1
DM
A 2
<< web app >>
A 1
A 2
Tests the journey a user will have to do something
useful in the system
Application is tested as a black box normally using
a BDD framework
Actions are faked. We just want to know if the
application presents the user with the correct
journey
Designed according to User Stories
and Features
<<fake>>
<<fake>>
![Page 36: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/36.jpg)
Infrastructure Impl
Testing strategies: Acceptance (Action / Behavioural)
A DS 1
<<mock>>
RDS 2 R
Tests a behaviour (action) provided by the system
Action is the entry point and
all external dependencies are
stubbed
Domain Model
Normally tested using a BDD
framework
![Page 37: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/37.jpg)
Testing strategies: Integration
Tests the classes at the system boundaries
Infrastructure Impl
A DS 1
<<mock>>
RDS 2 R
Domain Model
Normally done using an in-
memory Database using a unit
testing framework
![Page 38: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/38.jpg)
Testing strategies: Unit (Class level)
Unit test at class/method level
InfrastructureImpl
A DS 1
RRDS 2
Domain Model
DS 1
DS 2
All collaborators are
mocked / stubbed
(spies)
![Page 39: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/39.jpg)
Testing strategies: End-to-End
Model
A 1
R 3
DS 1
DS 3
R 1
S
Infrastructure Impl
DM
DS 2
Impl
A 2
<< web app >>
Full application deployed
Uses BDD framework, accessing a testing database and
fake external dependencies
Very few tests at this level, just to make sure
application is wired properly
![Page 40: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/40.jpg)
Use libraries, not frameworks
![Page 41: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/41.jpg)
The problem is not TDD. The problem is our
inability to design software well.
![Page 42: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/42.jpg)
C A DS R
Input Output
Execution Flow
Outside-In TDD
The closer to the input a class is, the more flow control and delegation it does.
The closer to the output a class is, the more specific it is and less delegation it does
Design Flow
cl
cl
cl cl
clDS
![Page 43: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/43.jpg)
Inner domain
Outer domain
(actions)
Ports &Adapters
Delivery mechanism
![Page 44: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/44.jpg)
Answering the two original questions
What is the application about? (main concepts)
What does the application do? (main capabilities)
Expressed by nouns
Expressed by verbs
(Actions)
![Page 45: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/45.jpg)
![Page 46: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/46.jpg)
![Page 47: Crafted Design - LJC World Tour Mash Up 2014](https://reader033.vdocuments.site/reader033/viewer/2022060121/559444551a28ab0c308b4783/html5/thumbnails/47.jpg)
Thank You
@sandromancuso