SlideShare ist ein Scribd-Unternehmen logo
1 von 17
Downloaden Sie, um offline zu lesen
Luca Milan
http://fewbit.com
 info@fewbit.com
“ At its worst business logic can be very complex. Rules and
  logic describe many different cases and slants of behavior,
  and it’s this complexity that objects were designed to work
  with. A Domain Model creates a web of interconnected
  objects, where each object represents some meaningful
  individual, whether as large as a corporation or as small as
  a single line on an order form”

Io leggo: usiamo tecniche OO per tradurre la complessità del
  dominio applicativo in un modello ad oggetti utile allo
  scopo (nessun virtuosismo concettuale dobbiamo essere
  pragmatici).
   Una disciplina che aiuta lo sviluppatore ad consolidare
    le logiche di business (complesse e in evoluzione) di
    un dominio applicativo in un Modello ad Oggetti grazie
    al paradigma OO .
   Un insieme di regole e principi che pone il Modello ad
    Oggetti come centro del processo di sviluppo.
   Uno stile architetturale che realizza un
    disaccoppiamento tra il Modello ad Oggetti e gli altri
    strati software rendendolo totalmente autonomo e
    indipendente.
   Possiamo farlo quando:
    ◦ Il processo di sviluppo è iterativo. Miglioreremo la conoscenza del
      dominio passo dopo passo grazie all’aiuto degli esperti del dominio.
    ◦ Le logiche di business del domino sono complesse ed evolvono
      continuamente nel tempo.
    ◦ Conosciamo bene la programmazione OO ed abbiamo familiarità
      con concetti come Refactoring, IOC, Persistence Ignorance (PI),
      principi SOLID, ecc..
   Non conviene usare la DDD quando:
    ◦ I progetti sono semplici (un blog, un piccolo e-commerce) e non
      subiscono evoluzioni nel tempo.
    ◦ Applicazioni di pura reportistica o ETL o simili
   Domain Model
    ◦ “An object model of the domain that incorporates both
      behavior and data” da Fowler
Una classe .NET incarna un
                                public class Ordine{
       object model                public string Cliente{get;set;}
                                   public void MarcaComeCompleto(){
    ◦ Attenzione:                     Stato = StatoOrdine.Completo;
                                   }
      Classe != Oggetto            public IList<Linee> {get;set;}
                                }


Una volta creati gli oggetti possiamo collegarli tramite gerarchie
 e relazioni ed assegnarli ruoli e responsabilità. Ciò significa
 formare la rete interconnessa (grafo) del pattern di Fowler.
   Bounded Context (or Context)
    ◦ “The delimited applicability of a particular model.
      BOUNDING CONTEXTS gives team members a clear and
      shared understanding of what has to be consistent and
      what can develop independently” da domaindrivendesign.org

    Rappresentano i confini (variabili) del dominio e devono
     essere ben marcati. Al di fuori di essi dobbiamo lasciare
     tutta la complessità non utile ai nostri scopi (funzionali ed
     applicativi). Non perdiamo la direzione!!!
   Parte di Catalogo di un domain model per un sistema di e-commerce
   Spesso i domain model non seguono le regole indicate
    da Fowler ed Evans, in questo caso Fowler identifica un
    anti-pattern: l’Anemic Domain Model
   I sintomi di un dominio anemico sono a livello di
    classe:
    1. Ad una 1 classe corrisponde una 1 tabella
    2. Non ci sono metodi solo getters e setters
    3. La logica anziché sui metodi viene incapsulata nei setters

    In questi casi dobbiamo rivitalizzare il dominio.
   Ubiquitous Language           Unit Of Work
   Entity                        Inversion Of Control
   Value Object                  Object Relational Mapping
                                  Aspected Oriented
   Repository
                                   Programming
   Service
                                  Contract By Design
   Aggregates                    TDD, BDD
   Factories                     OO tecniques, SOLID
   Specification / Queries        principles
   Context (Boundary / Map)      Refactoring

Attori della DDD               Patterns e tecniche collegate
   Sviluppatori ed esperti del dominio devono collaborare tra
    loro. Per farlo al meglio devono trovare un linguaggio
    comune semplice ed intuitivo con cui poter dialogare (no
    termini tecnici, no termini di business) .
                          Paginare,
                         Schedulare,
                         Indicizzare,
                        Disaccoppiare




                            CGA, Mandato ad
                             Assicurare, ecc..
   Dal libro di Eric Evans:

    1. "An Entity is an Object that represents something with
       continuity and identity. An entity is tracked through
       different states and implementations.“

    2. "An object that represents a descriptive aspect of the
       domain with no conceptual identity“
   Dal libro di Eric Evans

    “First we need an abstraction for encapsulating references
    within the [domain] model. An Aggregate is a cluster of
    associated [domain] objects that we treat as a unit for the
    purpose of [ensuring consistency of] data changes. Each
    Aggregate has a root and a boundary. The root is a single,
    specific Entity contained in the Aggregate”
   E’ uno dei concetti più dibattuti Fowler dice:
    “A Repository mediates between the domain and data mapping layers, acting
    like an in-memory domain object collection. Client objects construct query
    specifications declaratively and submit them to Repository for satisfaction.
    Objects can be added to and removed from the Repository, as they can from a
    simple collection of objects, and the mapping code encapsulated by the
    Repository will carry out the appropriate operations behind the scenes.
    Conceptually, a Repository encapsulates the set of objects persisted in a data
    store and the operations performed over them, providing a more object-
    oriented view of the persistence layer. Repository also supports the objective of
    achieving a clean separation and one-way dependency between the domain
    and data mapping layers”

Parla il linguaggio del domain model (no DTO no DAO) ed è agnostico rispetto ai
  meccanismi di persistenza utilizzati dall’applicazione. Rafforza il concetto di
  uguaglianza per Identità (non by reference), il repository restituisce la stessa
  istanza di oggetto se l’oggetto ha la stessa identità.
   Dal libro di Eric Evans

    “A SERVICE is an operation offered as an interface that stands
    alone in the model, without encapsulating state,
    as ENTITIES and VALUE OBJECTS do.“

Un servizio si occupa di coordinare azioni che coinvolgono uno o più oggetti
  del dominio (entity,value objects,repository). Es. La modifica di un ordine
  non può essere delegata ad un singolo comportamento dell’entità Ordine,
  meglio creare un servizio IOrderModify.Execute(params).
   Possiamo usare l’approccio DDD anche con altri tipi di
    architetture di classe enterprise:
    ◦ Con SOA vedi http://www.udidahan.com/
    ◦ In scenari distribuiti come Distributed DDD vedi
      http://codebetter.com/blogs/gregyoung/
    ◦ Con REST vedi
      http://blogs.msdn.com/jmeier/archive/2009/01/21/applicatio
      n-patterns.aspx
   http://www.infoq.com/presentations/model-to-work-
    evans
   http://domaindrivendesign.org/books
   http://www.infoq.com/interviews/jimmy-nilsson-
    domain-driven-design
   http://domaindrivendesign.org/
   http://download.microsoft.com/download/6/3/D/63D
    A97EC-6B79-42C1-9DAF-D8D00D8C7759/guisa.pdf
Approccio Pratico al Domain Driven Design

Weitere ähnliche Inhalte

Was ist angesagt?

Domain driven design
Domain driven designDomain driven design
Domain driven designtatyaso
 
Design Patterns - General Introduction
Design Patterns - General IntroductionDesign Patterns - General Introduction
Design Patterns - General IntroductionAsma CHERIF
 
Learning solid principles using c#
Learning solid principles using c#Learning solid principles using c#
Learning solid principles using c#Aditya Kumar Rajan
 
Service Oriented Architecture (SOA)
Service Oriented Architecture (SOA)Service Oriented Architecture (SOA)
Service Oriented Architecture (SOA)Mazhar Ishaq Khokhar
 
Design Patterns Presentation - Chetan Gole
Design Patterns Presentation -  Chetan GoleDesign Patterns Presentation -  Chetan Gole
Design Patterns Presentation - Chetan GoleChetan Gole
 
Introduction to design patterns
Introduction to design patternsIntroduction to design patterns
Introduction to design patternsAmit Kabra
 
09 package diagram
09 package diagram09 package diagram
09 package diagramBaskarkncet
 
Singleton design pattern
Singleton design patternSingleton design pattern
Singleton design pattern11prasoon
 
HP CloudSystem Matrix
HP CloudSystem MatrixHP CloudSystem Matrix
HP CloudSystem MatrixArun prasath
 
Domain Driven Design – DDD além da teoria!, por Paulo Victor Gomes
Domain Driven Design – DDD além da teoria!, por Paulo Victor GomesDomain Driven Design – DDD além da teoria!, por Paulo Victor Gomes
Domain Driven Design – DDD além da teoria!, por Paulo Victor GomesiMasters
 
Amazon & AWS의 MSA와 DevOps, 그리고 지속적 혁신
Amazon & AWS의 MSA와 DevOps, 그리고 지속적 혁신Amazon & AWS의 MSA와 DevOps, 그리고 지속적 혁신
Amazon & AWS의 MSA와 DevOps, 그리고 지속적 혁신AgileKoreaConference Alliance
 
Let us understand design pattern
Let us understand design patternLet us understand design pattern
Let us understand design patternMindfire Solutions
 
Service Oriented Architecture In Automotive
Service Oriented Architecture In AutomotiveService Oriented Architecture In Automotive
Service Oriented Architecture In AutomotiveNamrata Mahalingam
 
Java Course 11: Design Patterns
Java Course 11: Design PatternsJava Course 11: Design Patterns
Java Course 11: Design PatternsAnton Keks
 
Introduction to SOLID Principles
Introduction to SOLID PrinciplesIntroduction to SOLID Principles
Introduction to SOLID PrinciplesGanesh Samarthyam
 
Design Pattern For C# Part 1
Design Pattern For C# Part 1Design Pattern For C# Part 1
Design Pattern For C# Part 1Shahzad
 

Was ist angesagt? (20)

Design Patterns (Examples in .NET)
Design Patterns (Examples in .NET)Design Patterns (Examples in .NET)
Design Patterns (Examples in .NET)
 
Domain driven design
Domain driven designDomain driven design
Domain driven design
 
Design Patterns - General Introduction
Design Patterns - General IntroductionDesign Patterns - General Introduction
Design Patterns - General Introduction
 
Learning solid principles using c#
Learning solid principles using c#Learning solid principles using c#
Learning solid principles using c#
 
Service Oriented Architecture (SOA)
Service Oriented Architecture (SOA)Service Oriented Architecture (SOA)
Service Oriented Architecture (SOA)
 
Design Patterns Presentation - Chetan Gole
Design Patterns Presentation -  Chetan GoleDesign Patterns Presentation -  Chetan Gole
Design Patterns Presentation - Chetan Gole
 
Introduction to design patterns
Introduction to design patternsIntroduction to design patterns
Introduction to design patterns
 
09 package diagram
09 package diagram09 package diagram
09 package diagram
 
Singleton design pattern
Singleton design patternSingleton design pattern
Singleton design pattern
 
HP CloudSystem Matrix
HP CloudSystem MatrixHP CloudSystem Matrix
HP CloudSystem Matrix
 
Domain Driven Design – DDD além da teoria!, por Paulo Victor Gomes
Domain Driven Design – DDD além da teoria!, por Paulo Victor GomesDomain Driven Design – DDD além da teoria!, por Paulo Victor Gomes
Domain Driven Design – DDD além da teoria!, por Paulo Victor Gomes
 
Seq uml
Seq umlSeq uml
Seq uml
 
Amazon & AWS의 MSA와 DevOps, 그리고 지속적 혁신
Amazon & AWS의 MSA와 DevOps, 그리고 지속적 혁신Amazon & AWS의 MSA와 DevOps, 그리고 지속적 혁신
Amazon & AWS의 MSA와 DevOps, 그리고 지속적 혁신
 
Let us understand design pattern
Let us understand design patternLet us understand design pattern
Let us understand design pattern
 
Service Oriented Architecture In Automotive
Service Oriented Architecture In AutomotiveService Oriented Architecture In Automotive
Service Oriented Architecture In Automotive
 
Gof design patterns
Gof design patternsGof design patterns
Gof design patterns
 
Java Course 11: Design Patterns
Java Course 11: Design PatternsJava Course 11: Design Patterns
Java Course 11: Design Patterns
 
Solid Principles
Solid PrinciplesSolid Principles
Solid Principles
 
Introduction to SOLID Principles
Introduction to SOLID PrinciplesIntroduction to SOLID Principles
Introduction to SOLID Principles
 
Design Pattern For C# Part 1
Design Pattern For C# Part 1Design Pattern For C# Part 1
Design Pattern For C# Part 1
 

Ähnlich wie Approccio Pratico al Domain Driven Design

How I did it (in .NET): idiomatic Domain Driven Design
How I did it (in .NET): idiomatic Domain Driven DesignHow I did it (in .NET): idiomatic Domain Driven Design
How I did it (in .NET): idiomatic Domain Driven DesignAndrea Saltarello
 
Repository pattern slides v1.1
Repository pattern slides v1.1Repository pattern slides v1.1
Repository pattern slides v1.1Christian Nastasi
 
Domain Driven Design e CQRS
Domain Driven Design e CQRSDomain Driven Design e CQRS
Domain Driven Design e CQRSManuel Scapolan
 
Idiomatic Domain Driven Design
Idiomatic Domain Driven DesignIdiomatic Domain Driven Design
Idiomatic Domain Driven DesignAndrea Saltarello
 
Never Mind the Bollocks: here's the Domain Driven Design
Never Mind the Bollocks: here's the Domain Driven DesignNever Mind the Bollocks: here's the Domain Driven Design
Never Mind the Bollocks: here's the Domain Driven DesignAndrea Saltarello
 
Note di Data Warehouse e Business Intelligence - Tecniche di Naming Conventio...
Note di Data Warehouse e Business Intelligence - Tecniche di Naming Conventio...Note di Data Warehouse e Business Intelligence - Tecniche di Naming Conventio...
Note di Data Warehouse e Business Intelligence - Tecniche di Naming Conventio...Massimo Cenci
 
Slide evento Code Refactoring JavaScript
Slide evento Code Refactoring JavaScriptSlide evento Code Refactoring JavaScript
Slide evento Code Refactoring JavaScriptLuca Pagliaro
 
C#, imparare a programmare e sopravvivere
C#, imparare a programmare e sopravvivereC#, imparare a programmare e sopravvivere
C#, imparare a programmare e sopravvivereMatteo Valoriani
 
Entity Framework 4.0 vs NHibernate
Entity Framework 4.0 vs NHibernateEntity Framework 4.0 vs NHibernate
Entity Framework 4.0 vs NHibernateManuel Scapolan
 
Riuso Object Oriented
Riuso Object OrientedRiuso Object Oriented
Riuso Object OrientedStefano Fago
 
Modelli applicativi per il Cloud Computing - Part 1 - Edition 2014
Modelli applicativi per il Cloud Computing - Part 1 - Edition 2014Modelli applicativi per il Cloud Computing - Part 1 - Edition 2014
Modelli applicativi per il Cloud Computing - Part 1 - Edition 2014Marco Parenzan
 
Code Contracts and Generics: implementing a LINQ-enabled Repository
Code Contracts and Generics: implementing a LINQ-enabled RepositoryCode Contracts and Generics: implementing a LINQ-enabled Repository
Code Contracts and Generics: implementing a LINQ-enabled RepositoryAndrea Saltarello
 
Build a LINQ-enabled Repository
Build a LINQ-enabled RepositoryBuild a LINQ-enabled Repository
Build a LINQ-enabled RepositoryAndrea Saltarello
 
Layered Expression Trees: una terza via (idiomatica) verso il DDD
Layered Expression Trees: una terza via (idiomatica) verso il DDDLayered Expression Trees: una terza via (idiomatica) verso il DDD
Layered Expression Trees: una terza via (idiomatica) verso il DDDAndrea Saltarello
 
Java Programming Language
Java Programming LanguageJava Programming Language
Java Programming LanguagePasquale Paola
 
Layered Expression Trees feat. CQRS
Layered Expression Trees feat. CQRSLayered Expression Trees feat. CQRS
Layered Expression Trees feat. CQRSAndrea Saltarello
 

Ähnlich wie Approccio Pratico al Domain Driven Design (20)

How I did it (in .NET): idiomatic Domain Driven Design
How I did it (in .NET): idiomatic Domain Driven DesignHow I did it (in .NET): idiomatic Domain Driven Design
How I did it (in .NET): idiomatic Domain Driven Design
 
Repository pattern slides v1.1
Repository pattern slides v1.1Repository pattern slides v1.1
Repository pattern slides v1.1
 
Domain Driven Design e CQRS
Domain Driven Design e CQRSDomain Driven Design e CQRS
Domain Driven Design e CQRS
 
Idiomatic Domain Driven Design
Idiomatic Domain Driven DesignIdiomatic Domain Driven Design
Idiomatic Domain Driven Design
 
Never Mind the Bollocks: here's the Domain Driven Design
Never Mind the Bollocks: here's the Domain Driven DesignNever Mind the Bollocks: here's the Domain Driven Design
Never Mind the Bollocks: here's the Domain Driven Design
 
Note di Data Warehouse e Business Intelligence - Tecniche di Naming Conventio...
Note di Data Warehouse e Business Intelligence - Tecniche di Naming Conventio...Note di Data Warehouse e Business Intelligence - Tecniche di Naming Conventio...
Note di Data Warehouse e Business Intelligence - Tecniche di Naming Conventio...
 
ORM - Introduzione
ORM - IntroduzioneORM - Introduzione
ORM - Introduzione
 
Corso UML
Corso UMLCorso UML
Corso UML
 
Slide evento Code Refactoring JavaScript
Slide evento Code Refactoring JavaScriptSlide evento Code Refactoring JavaScript
Slide evento Code Refactoring JavaScript
 
C#, imparare a programmare e sopravvivere
C#, imparare a programmare e sopravvivereC#, imparare a programmare e sopravvivere
C#, imparare a programmare e sopravvivere
 
Entity Framework 4.0 vs NHibernate
Entity Framework 4.0 vs NHibernateEntity Framework 4.0 vs NHibernate
Entity Framework 4.0 vs NHibernate
 
Riuso Object Oriented
Riuso Object OrientedRiuso Object Oriented
Riuso Object Oriented
 
Repository pattern
Repository patternRepository pattern
Repository pattern
 
Modelli applicativi per il Cloud Computing - Part 1 - Edition 2014
Modelli applicativi per il Cloud Computing - Part 1 - Edition 2014Modelli applicativi per il Cloud Computing - Part 1 - Edition 2014
Modelli applicativi per il Cloud Computing - Part 1 - Edition 2014
 
Code Contracts and Generics: implementing a LINQ-enabled Repository
Code Contracts and Generics: implementing a LINQ-enabled RepositoryCode Contracts and Generics: implementing a LINQ-enabled Repository
Code Contracts and Generics: implementing a LINQ-enabled Repository
 
Build a LINQ-enabled Repository
Build a LINQ-enabled RepositoryBuild a LINQ-enabled Repository
Build a LINQ-enabled Repository
 
Layered Expression Trees: una terza via (idiomatica) verso il DDD
Layered Expression Trees: una terza via (idiomatica) verso il DDDLayered Expression Trees: una terza via (idiomatica) verso il DDD
Layered Expression Trees: una terza via (idiomatica) verso il DDD
 
Java Programming Language
Java Programming LanguageJava Programming Language
Java Programming Language
 
Object Oriented Design
Object Oriented DesignObject Oriented Design
Object Oriented Design
 
Layered Expression Trees feat. CQRS
Layered Expression Trees feat. CQRSLayered Expression Trees feat. CQRS
Layered Expression Trees feat. CQRS
 

Mehr von Luca Milan

Enabling DevOps for Machine Learning with Azure Pipelines
Enabling DevOps for Machine Learning with Azure PipelinesEnabling DevOps for Machine Learning with Azure Pipelines
Enabling DevOps for Machine Learning with Azure PipelinesLuca Milan
 
"Don't call us, we'll call you" - AngularJS meets Event-Driven Architecture
"Don't call us, we'll call you" - AngularJS meets Event-Driven Architecture"Don't call us, we'll call you" - AngularJS meets Event-Driven Architecture
"Don't call us, we'll call you" - AngularJS meets Event-Driven ArchitectureLuca Milan
 
Azure WebSites for Developers
Azure WebSites for DevelopersAzure WebSites for Developers
Azure WebSites for DevelopersLuca Milan
 
Web Api – The HTTP Way
Web Api – The HTTP WayWeb Api – The HTTP Way
Web Api – The HTTP WayLuca Milan
 
AngularJS – Reinventare le applicazioni web
AngularJS – Reinventare le applicazioni webAngularJS – Reinventare le applicazioni web
AngularJS – Reinventare le applicazioni webLuca Milan
 
Il difficile mestiere dello sviluppatore: un approccio feature oriented.
Il difficile mestiere dello sviluppatore: un approccio feature oriented.Il difficile mestiere dello sviluppatore: un approccio feature oriented.
Il difficile mestiere dello sviluppatore: un approccio feature oriented.Luca Milan
 
What's new in Asp.Net 4.5 (and WebApi)
What's new in Asp.Net 4.5 (and WebApi)What's new in Asp.Net 4.5 (and WebApi)
What's new in Asp.Net 4.5 (and WebApi)Luca Milan
 
Usare le nuove WCF Web Api per creare servizi RESTful
Usare le nuove WCF Web Api per creare servizi RESTfulUsare le nuove WCF Web Api per creare servizi RESTful
Usare le nuove WCF Web Api per creare servizi RESTfulLuca Milan
 
NHibernate Configuration Patterns
NHibernate Configuration PatternsNHibernate Configuration Patterns
NHibernate Configuration PatternsLuca Milan
 
Architetttura Della Soluzione
Architetttura Della SoluzioneArchitetttura Della Soluzione
Architetttura Della SoluzioneLuca Milan
 

Mehr von Luca Milan (10)

Enabling DevOps for Machine Learning with Azure Pipelines
Enabling DevOps for Machine Learning with Azure PipelinesEnabling DevOps for Machine Learning with Azure Pipelines
Enabling DevOps for Machine Learning with Azure Pipelines
 
"Don't call us, we'll call you" - AngularJS meets Event-Driven Architecture
"Don't call us, we'll call you" - AngularJS meets Event-Driven Architecture"Don't call us, we'll call you" - AngularJS meets Event-Driven Architecture
"Don't call us, we'll call you" - AngularJS meets Event-Driven Architecture
 
Azure WebSites for Developers
Azure WebSites for DevelopersAzure WebSites for Developers
Azure WebSites for Developers
 
Web Api – The HTTP Way
Web Api – The HTTP WayWeb Api – The HTTP Way
Web Api – The HTTP Way
 
AngularJS – Reinventare le applicazioni web
AngularJS – Reinventare le applicazioni webAngularJS – Reinventare le applicazioni web
AngularJS – Reinventare le applicazioni web
 
Il difficile mestiere dello sviluppatore: un approccio feature oriented.
Il difficile mestiere dello sviluppatore: un approccio feature oriented.Il difficile mestiere dello sviluppatore: un approccio feature oriented.
Il difficile mestiere dello sviluppatore: un approccio feature oriented.
 
What's new in Asp.Net 4.5 (and WebApi)
What's new in Asp.Net 4.5 (and WebApi)What's new in Asp.Net 4.5 (and WebApi)
What's new in Asp.Net 4.5 (and WebApi)
 
Usare le nuove WCF Web Api per creare servizi RESTful
Usare le nuove WCF Web Api per creare servizi RESTfulUsare le nuove WCF Web Api per creare servizi RESTful
Usare le nuove WCF Web Api per creare servizi RESTful
 
NHibernate Configuration Patterns
NHibernate Configuration PatternsNHibernate Configuration Patterns
NHibernate Configuration Patterns
 
Architetttura Della Soluzione
Architetttura Della SoluzioneArchitetttura Della Soluzione
Architetttura Della Soluzione
 

Approccio Pratico al Domain Driven Design

  • 2. “ At its worst business logic can be very complex. Rules and logic describe many different cases and slants of behavior, and it’s this complexity that objects were designed to work with. A Domain Model creates a web of interconnected objects, where each object represents some meaningful individual, whether as large as a corporation or as small as a single line on an order form” Io leggo: usiamo tecniche OO per tradurre la complessità del dominio applicativo in un modello ad oggetti utile allo scopo (nessun virtuosismo concettuale dobbiamo essere pragmatici).
  • 3. Una disciplina che aiuta lo sviluppatore ad consolidare le logiche di business (complesse e in evoluzione) di un dominio applicativo in un Modello ad Oggetti grazie al paradigma OO .  Un insieme di regole e principi che pone il Modello ad Oggetti come centro del processo di sviluppo.  Uno stile architetturale che realizza un disaccoppiamento tra il Modello ad Oggetti e gli altri strati software rendendolo totalmente autonomo e indipendente.
  • 4. Possiamo farlo quando: ◦ Il processo di sviluppo è iterativo. Miglioreremo la conoscenza del dominio passo dopo passo grazie all’aiuto degli esperti del dominio. ◦ Le logiche di business del domino sono complesse ed evolvono continuamente nel tempo. ◦ Conosciamo bene la programmazione OO ed abbiamo familiarità con concetti come Refactoring, IOC, Persistence Ignorance (PI), principi SOLID, ecc..  Non conviene usare la DDD quando: ◦ I progetti sono semplici (un blog, un piccolo e-commerce) e non subiscono evoluzioni nel tempo. ◦ Applicazioni di pura reportistica o ETL o simili
  • 5. Domain Model ◦ “An object model of the domain that incorporates both behavior and data” da Fowler Una classe .NET incarna un public class Ordine{ object model public string Cliente{get;set;} public void MarcaComeCompleto(){ ◦ Attenzione: Stato = StatoOrdine.Completo; } Classe != Oggetto public IList<Linee> {get;set;} } Una volta creati gli oggetti possiamo collegarli tramite gerarchie e relazioni ed assegnarli ruoli e responsabilità. Ciò significa formare la rete interconnessa (grafo) del pattern di Fowler.
  • 6. Bounded Context (or Context) ◦ “The delimited applicability of a particular model. BOUNDING CONTEXTS gives team members a clear and shared understanding of what has to be consistent and what can develop independently” da domaindrivendesign.org Rappresentano i confini (variabili) del dominio e devono essere ben marcati. Al di fuori di essi dobbiamo lasciare tutta la complessità non utile ai nostri scopi (funzionali ed applicativi). Non perdiamo la direzione!!!
  • 7. Parte di Catalogo di un domain model per un sistema di e-commerce
  • 8. Spesso i domain model non seguono le regole indicate da Fowler ed Evans, in questo caso Fowler identifica un anti-pattern: l’Anemic Domain Model  I sintomi di un dominio anemico sono a livello di classe: 1. Ad una 1 classe corrisponde una 1 tabella 2. Non ci sono metodi solo getters e setters 3. La logica anziché sui metodi viene incapsulata nei setters In questi casi dobbiamo rivitalizzare il dominio.
  • 9. Ubiquitous Language  Unit Of Work  Entity  Inversion Of Control  Value Object  Object Relational Mapping  Aspected Oriented  Repository Programming  Service  Contract By Design  Aggregates  TDD, BDD  Factories  OO tecniques, SOLID  Specification / Queries principles  Context (Boundary / Map)  Refactoring Attori della DDD Patterns e tecniche collegate
  • 10. Sviluppatori ed esperti del dominio devono collaborare tra loro. Per farlo al meglio devono trovare un linguaggio comune semplice ed intuitivo con cui poter dialogare (no termini tecnici, no termini di business) . Paginare, Schedulare, Indicizzare, Disaccoppiare CGA, Mandato ad Assicurare, ecc..
  • 11. Dal libro di Eric Evans: 1. "An Entity is an Object that represents something with continuity and identity. An entity is tracked through different states and implementations.“ 2. "An object that represents a descriptive aspect of the domain with no conceptual identity“
  • 12. Dal libro di Eric Evans “First we need an abstraction for encapsulating references within the [domain] model. An Aggregate is a cluster of associated [domain] objects that we treat as a unit for the purpose of [ensuring consistency of] data changes. Each Aggregate has a root and a boundary. The root is a single, specific Entity contained in the Aggregate”
  • 13. E’ uno dei concetti più dibattuti Fowler dice: “A Repository mediates between the domain and data mapping layers, acting like an in-memory domain object collection. Client objects construct query specifications declaratively and submit them to Repository for satisfaction. Objects can be added to and removed from the Repository, as they can from a simple collection of objects, and the mapping code encapsulated by the Repository will carry out the appropriate operations behind the scenes. Conceptually, a Repository encapsulates the set of objects persisted in a data store and the operations performed over them, providing a more object- oriented view of the persistence layer. Repository also supports the objective of achieving a clean separation and one-way dependency between the domain and data mapping layers” Parla il linguaggio del domain model (no DTO no DAO) ed è agnostico rispetto ai meccanismi di persistenza utilizzati dall’applicazione. Rafforza il concetto di uguaglianza per Identità (non by reference), il repository restituisce la stessa istanza di oggetto se l’oggetto ha la stessa identità.
  • 14. Dal libro di Eric Evans “A SERVICE is an operation offered as an interface that stands alone in the model, without encapsulating state, as ENTITIES and VALUE OBJECTS do.“ Un servizio si occupa di coordinare azioni che coinvolgono uno o più oggetti del dominio (entity,value objects,repository). Es. La modifica di un ordine non può essere delegata ad un singolo comportamento dell’entità Ordine, meglio creare un servizio IOrderModify.Execute(params).
  • 15. Possiamo usare l’approccio DDD anche con altri tipi di architetture di classe enterprise: ◦ Con SOA vedi http://www.udidahan.com/ ◦ In scenari distribuiti come Distributed DDD vedi http://codebetter.com/blogs/gregyoung/ ◦ Con REST vedi http://blogs.msdn.com/jmeier/archive/2009/01/21/applicatio n-patterns.aspx
  • 16. http://www.infoq.com/presentations/model-to-work- evans  http://domaindrivendesign.org/books  http://www.infoq.com/interviews/jimmy-nilsson- domain-driven-design  http://domaindrivendesign.org/  http://download.microsoft.com/download/6/3/D/63D A97EC-6B79-42C1-9DAF-D8D00D8C7759/guisa.pdf