Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
ESQHTQUF? 

 

Sandro Mancuso
@sandromancuso
http: /⁄| eanpub. com/ socra
> What is this application about? 

<> What are the main concepts? 

> What does this application do? 
<> What are the mai...
IJ/ nf 's year

PROBLEM

   
  

> Looking from above,  I can't see what the application
does or is about

> Architectural...
Example:  Layered structure

Y  crafteddes ig_layered
V i src/ main/ java

b I cormcodurancexontrollers
b l comxodurancada...
Example:  Layered-domain structure

V  crafteddes ign_d omainJaye red

V 'src/ main/ java
b I comxoduranceboolncontrol ler...
Example:  MVC structure

crafteddesign_mvc_| ayered

j* src/ main/ java
 com. codurancexontrollers
å] com. codurancacontro...
MVC & MVC Variations

MVC (Smalltalk 76/80)

MVC (general concept - 1988)

Three-Tier Architecture (Presentation,  Logic, ...
tcliiljgllirlâi
uvmii W FIF

'iiülinlähll-C m'

; ii-nuanizfi-, v

fi-juiulâliri
MVC & MVC Variations

IIGHT WIONG

Witt

They are all right.  And they are wrong.  lt all depends on the 'V'iew.
V' Vi' V' V' V' V' V'

Views impact MVC structure

Depending on the view technology,  Views and Controllers
responsibility...
MVC - A Macro Organisational Pattern

V C M

DDI

Delivery
Mechanism
“Model" is overloaded and confusing

» Model (M in MVC)

> Domain Model (DDD)
> View Model

» Data Model

> Entities & Act...
M = > Domain Model (DDD)

Domain Model combines state and
behaviour,  with more focus on the latter. 

DDD define a few bu...
Embedded Domain Model

« Web app »

Delivery
Mechanism
Deployable Domain Model

« deployable app »

« mobile app ›>

«W/ S»

« extemal system »

 

Delivery
Mechanisms
Event-Driven Domain Model

«event 1»

« external app1 » « dePbYable app »

« extemal app 2 »

V 
E Infrastructure l

    
...
Domain Model
building blocks & responsibilities

>
>
o. 
D. 
a
b
e
w
<
<

[QS

 

Infrastructure

A =  Action,  DS =  Doma...
Behaviour:  Action,  Domain Service or Entity? 

“Detines the action our domain modet

Action will.  be asked to Perçorm. ...
Repositories (not DAOs)

Domain Model

›: .<r0pository: ›> «repository»

 

«OracIe» «Mongo»
Infrastructure Users Books

"...
An example would be good. ..

User Account
Service
Payment
Gateway

Order
Service

«interface»
Email Sender

l: lAction E]...
Class responsibility

Domain Model
entr-j point

'Domain Concept

thtrj FOLME ëaââiâçcâkáâe OutFut

  
  

Input Output
Fi...
Domain Model collaborations guideline

4

'V

 
 

4
z
x'

    

"X".  Except for read model. 

C =  Controller,  A =  Act...
Command & Query Actions

«Write Model»

 

« web app »

få
So,  how does the app structure look like? 

V Dsrc
v Djava
v Dcomxodurance
b Dinfrastrucmre
V Dsrc › Drnodel

b D core b ...
eb project responsibility
Delivery Mechanism:  Defines the user journey
i web ⁄

13W* Control flow (invoke actions)
comxod...
Core responsibility (simple project)

V D src
li]
v D java
Y Dcomxodurance

V El inffêslfüdüfe Tells what the system is ab...
Core responsibility (bigger project)
i

java
com. codurance
infrastru ctu re
mod el
payme nt
products
book
eletronics
'use...
What is inside model packages? 

comxodurance
infrastructure

i

payment

products Entity (part of Book aggregate)
g book ...
What is inside infrastructure? 
[ëgfinfrastructure

parsers
C BookToJSON
C UserToXML

repositories

,  Repository implemen...
Defining testing strategies and boundaries

Types of tests

- Unit

- Integration

- Acceptance
Journey
Black box
Componen...
Testing strategies:  User Journey

Tests the aaurnev a user will.  have lto
do sonet 3 useful 'sn the system

'Designed ac...
Testing strategies:  Acceptance (Action /  Behavioural)
Tests at behaviour (Action) provided bs,  the system

Domain Model...
Testing strategies:  Integration

Tests the classes at the s-, stem boundaries
Domain Model

normally done using
an Ln-mev...
Testing strategies:  Unit (Class level)
Unit test at class/ method Level. 

Domain Model

All collaborators
are mocked ⁄
S...
: End-to-End

Testing strategies

Full a FFLication cieptonjed

e
r
U
. Ti
C
U
r. 
T. 
S
m
. ..I
m

 

Vers;  ten. ) tests...
lnteraction-Driven Design - IDD
(Outside-In design)

Input Output

“Eli

cl

 
 

Execution Flow

l
r
Design Flow 

”r Sta...
Answering the two original questions

> What is the application about?  (main concepts)

model

pdymcnt
products

book

. ...
SOFTWARE
CRAFTSMANSHIP

Thank You

@sandromancuso

'41

PRDFESSIDNALISM
PRABMATISM

 i:   clurani: 

Craft atheart

SANDRD...
Crafted design
Upcoming SlideShare
Loading in …5
×

Crafted design

In these slides Sandro shares how he designed the last application he worked on, twisting a few concepts from Domain-Driven Design, properly applying MVC, borrowing concepts from CQRS, and structuring packages in non-conventional ways. Sandro will also be touching on SOLID principles, Agile incremental design, modularisation, and testing. By iteratively modifying the project structure to better model the product requirements, he has come up with a design style that helps developers create maintainable and domain-oriented software.

  • Login to see the comments

  • Be the first to like this

Crafted design

  1. 1. ESQHTQUF? Sandro Mancuso @sandromancuso http: /⁄| eanpub. com/ socra
  2. 2. > What is this application about? <> What are the main concepts? > What does this application do? <> What are the main features? > Where do I need to change? <> Where do I put a new feature? . i
  3. 3. IJ/ nf 's year PROBLEM > Looking from above, I can't see what the application does or is about > Architectural and design concepts mixed with domain > Badly structured packages/ namespaces > I don't know where to start <> Classes and methods are too low level
  4. 4. Example: Layered structure Y crafteddes ig_layered V i src/ main/ java b I cormcodurancexontrollers b l comxodurancadao b I comxodurancejactories b I comcodurancmhelpers b I comxodurancemodel b I comxodurancimpageobject b I com. codurance. parsers b I corrncoduranceservices Csrclrnalnlresources 3 src/ test/ java i srcltest/ resources
  5. 5. Example: Layered-domain structure V crafteddes ign_d omainJaye red V 'src/ main/ java b I comxoduranceboolncontrol ler b . com. codurance. book. dao b l com. codurance. book. entity b I comxodurancebookfactory b I comcodurancebookhelper b I comcoduranceboolçparser b . com. codurance. book. service b u comcoduranccusencontroller b I comxodurancemsendao b I comcodurancemsencntity b I comcoduranccusenfactory b I comxoduranceusenhelper b I comxodurancemsenparscr b I comxodurancemsenservice b Csrc/ main/ resources b i src/ testljava b C srcIIesl/ resources
  6. 6. Example: MVC structure crafteddesign_mvc_| ayered j* src/ main/ java com. codurancexontrollers å] com. codurancacontrollers. util F; com. codurance. model. daos fj] com. codurancemodckhelper com. codurancemodeLparser com. codurancemodeLservices 55 com. codurance. view. helpers com. coduranceyiewpageobjets com. codurance. view. parsers f* src/ main/ resources j* src/ test/ java f* src/ test/ resources
  7. 7. 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 ViewModeI (MWM) Presentation-Abstraction-Control (PAC)
  8. 8. tcliiljgllirlâi uvmii W FIF 'iiülinlähll-C m' ; ii-nuanizfi-, v fi-juiulâliri
  9. 9. MVC & MVC Variations IIGHT WIONG Witt They are all right. And they are wrong. lt all depends on the 'V'iew.
  10. 10. V' Vi' V' V' V' V' V' Views impact MVC structure Depending on the view technology, Views and Controllers responsibility becomes more/ less coupled or blurred. 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.
  11. 11. MVC - A Macro Organisational Pattern V C M DDI Delivery Mechanism
  12. 12. “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?
  13. 13. 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 Services Value Objects <> Application Factories ° D°mam Repositories V. <> Infrastructure i* Aggregates l Ål
  14. 14. Embedded Domain Model « Web app » Delivery Mechanism
  15. 15. Deployable Domain Model « deployable app » « mobile app ›> «W/ S» « extemal system » Delivery Mechanisms
  16. 16. Event-Driven Domain Model «event 1» « external app1 » « dePbYable app » « extemal app 2 » V E Infrastructure l Mechanisms «event 2»
  17. 17. Domain Model building blocks & responsibilities > > o. D. a b e w < < [QS Infrastructure A = Action, DS = Domain Service, S = Infra. Service, R = Repository
  18. 18. Behaviour: Action, Domain Service or Entity? “Detines the action our domain modet Action will. be asked to Perçorm. Behaviour related to muLtiFLe instances of Domain the same ehtitv or difterent entities. Service Behaviour that doesnt fit an-j specific entituj. Behaviour related to the data of a single instance of an entit-j QIW
  19. 19. Repositories (not DAOs) Domain Model ›: .<r0pository: ›> «repository» «OracIe» «Mongo» Infrastructure Users Books "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
  20. 20. An example would be good. .. User Account Service Payment Gateway Order Service «interface» Email Sender l: lAction E] Domain Service [j Infra. Service D Repository D Class valid account? has prime account? Make Payment Payment Validator «interface» Card Processor store order process card email conñmiation
  21. 21. Class responsibility Domain Model entr-j point 'Domain Concept thtrj FOLME ëaââiâçcâkáâe OutFut Input Output First to handle input v Start Oi EM* “O” End of code branch Execution Flow L, .. ”r 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). “r Closer to the output / end of branch: Specific and detailed behaviour, no delegation, lower level abstraction (e. g. Parse XML (Parser), Create User (Repository))
  22. 22. Domain Model collaborations guideline 4 'V 4 z x' "X". Except for read model. C = Controller, A = Action, DS = Domain Service, R = Repository, cl = class
  23. 23. Command & Query Actions «Write Model» « web app » få
  24. 24. So, how does the app structure look like? V Dsrc v Djava v Dcomxodurance b Dinfrastrucmre V Dsrc › Drnodel b D core b D actions m core-te st D re sources P' Deore test › : men T ' ' , , : i Dweb_tes , Djava V D comxodurance D controlle rs D infrastructure D vlew D re sources b D we bapp b EI web_test
  25. 25. eb project responsibility Delivery Mechanism: Defines the user journey i web ⁄ 13W* Control flow (invoke actions) comxodurance controllers J SON XML parsers or converters I /7 infrastructure Vlew o› View Models, validators, etc resources Webapp fra Static files css img js WEB-INF we b_te st
  26. 26. Core responsibility (simple project) V D src li] v D java Y Dcomxodurance V El inffêslfüdüfe Tells what the system is about v E] model › D book › D user v D actions g q, Addgoogaowishust Tells what the system does 'o SearchBooks “b Updateuser Dresources
  27. 27. Core responsibility (bigger project) i java com. codurance infrastru ctu re mod el payme nt products book eletronics 'user actions ⁄ Epic / Theme p rod ucts u FindRecommendations C 5emh Epic / Theme purchase C AddBookToWishList C MakePayme nt _ ValidateCr Epic / Theme user_accounts C Updateuser , Related domain concepts
  28. 28. What is inside model packages? comxodurance infrastructure i payment products Entity (part of Book aggregate) g book ⁄ . - Author/ a Aggregate root (entity) Book . __, ,,_, ._. -› Re osito Bookcollectton p ry v: BookSen/ jçe __. _;-_-> DOmaln serVlCe C Bmkvandatm" D Part of aggregate behaviour <1 Genre › ieletronics user Address User --»-› Aggregate root (entity) I Users D - › Repository i: UserService actions x Domain Service Value Object (part of Book aggregate) ae Value Object (part of User aggregate)
  29. 29. What is inside infrastructure? [ëgfinfrastructure parsers C BookToJSON C UserToXML repositories , Repository implementations C GigaSpacesUse rs C MongoDBBookCollection services creditcards . , CreditCardProcessor implementations C AMEX Processor C VisaProcessor C PaymentQueue Liste ner C SMTPEmailSender model . _ paymem Interfaces defined by the domain. Dependency Inversion Principle (DlP) I CreditCardProcessor I EmailSe nd e r C PaymentGateway
  30. 30. Defining testing strategies and boundaries Types of tests - Unit - Integration - Acceptance Journey Black box Component System I - Functional Alpha Beta Conformance O O O O l O l O
  31. 31. Testing strategies: User Journey Tests the aaurnev a user will. have lto do sonet 3 useful 'sn the system 'Designed according bo User Sêories and Features _ Actions dre famed. We just onani: bo tcokmn i. : tested as a black box ma" ; Æ u* *PFL a lcotton resenha Hw. “° “$53 “ abb f""“°“'°"' user »ikk the galt-red: jourrneg rmolL-J
  32. 32. Testing strategies: Acceptance (Action / Behavioural) Tests at behaviour (Action) provided bs, the system Domain Model i, m Action is the entrj Point and all ext: dnmáencies Arc st Normalt. tested using a BBD tpameæork Infrastructure
  33. 33. Testing strategies: Integration Tests the classes at the s-, stem boundaries Domain Model normally done using an Ln-mevnor 'Database using a unit Eesting frotmeoork æ U f. C U . U æ r. :I h
  34. 34. Testing strategies: Unit (Class level) Unit test at class/ method Level. Domain Model All collaborators are mocked ⁄ Stubbed (spies) Infrastructure
  35. 35. : End-to-End Testing strategies Full a FFLication cieptonjed e r U . Ti C U r. T. S m . ..I m Vers; ten. ) tests at thi: levet, just to make : má aFFLicatLon i: »aired Froperlj Use: BED trameuorlz, accessing a testing database and take external cÅeFQMcÅGLMCLk-. i
  36. 36. lnteraction-Driven Design - IDD (Outside-In design) Input Output “Eli cl Execution Flow l r Design Flow ”r Starting from the action, model the expected behaviour (outside-in) ”r Entities (data structures) will emerge in order to satisfy the behaviour 'r Focus is on the behaviour of the system and not on how data is stored/ related
  37. 37. Answering the two original questions > What is the application about? (main concepts) model pdymcnt products book . eletronics user > What does the application do? (main features) Expressed bj nouns actions products FindRecommendatlons SearchBooks pwchase AddBookToWishList Ex Fra 5 5 ad Vgrb 5 MakePayment '_ - Val dateCreditCard (ACLLOVKS) usegaccouwts UbdateUser
  38. 38. SOFTWARE CRAFTSMANSHIP Thank You @sandromancuso '41 PRDFESSIDNALISM PRABMATISM i: clurani: Craft atheart SANDRD MANCUSD http: ⁄⁄| eanpub. com⁄socra

×