SlideShare a Scribd company logo
1 of 25
Download to read offline
Domain Driven Design
                       Antonio Terreno
                            Javaday
                    1 December 2007, Rome




Javaday Roma 2007        © ThoughtWorks, 2007
Javaday Roma 2007

                     Software design is art




“Software design is an art, and like any art it cannot be taught and learned
   as a precise science, by means of theorems and formulas.”
                                                            Floyd Marinescu




     Javaday Roma 2007          © ThoughtWorks, 2007
Javaday Roma 2007

                           The Agile Way
• No upfront design, requirement gathering
• The team makes the design
• Participation with the stakeholder


• Simple, what is simple for you?
• What is good for you?
• Refactoring, refactoring how? (dev skills)
• Refactoring how much? (fear)




     Javaday Roma 2007         © ThoughtWorks, 2007
Javaday Roma 2007

                 Domain Driven Development
• Focus on the domain
• A common language
• Layered architecture
• Entities / Value Objects
• Services
• Modules
• Aggregates
• Factories
• Repositories




     Javaday Roma 2007       © ThoughtWorks, 2007
Javaday Roma 2007

                              Domain Driven
• Layered architecture
   – User interface
   – Application Layer
       • No business logic
       • No State of business objects
       • Holds state of an application task progress
   – Domain Layer
       • Info about the domain
       • State is held here
   – Infrastructure Layer
       • Communication between layers
       • Persistence for business objects
       • Support libraries



    Javaday Roma 2007               © ThoughtWorks, 2007
Javaday Roma 2007

                            Why layers?
• Manage changes
• Avoids coupling of code
• Avoids unexpected behaviors after changes




    Javaday Roma 2007        © ThoughtWorks, 2007
Javaday Roma 2007

                                  Entities
• Objects that have an identity
• Spanning the life of the system and even after
• a Person object for example
• The Id does never change
• Some domain objects have already the concept of id
    – National number, airport code, …




• All the domain objects are then entities?




     Javaday Roma 2007          © ThoughtWorks, 2007
Javaday Roma 2007

                                                User
public class User {
   private string name;
   private bool isAuthorised;
   private readonly IList myPermissions = new List<Permission>();
   protected Guid id;


   public User(string name, bool isAuthorised, params Permission[] permissions)
   {
        id = Guid.Empty;
        this.name = name;
        this.isAuthorised = isAuthorised;
        SetPermissions(permissions);
   }




       Javaday Roma 2007                    © ThoughtWorks, 2007
Javaday Roma 2007

                               Value Objects
• When we care about what an object has and not about which object is
   – How and when write a VO?
       • First we write a VO when the object is NOT an Entity!
       • Will be great if a VO is immutable
       • For performance but mostly
       • They will manifest integrity
       • If value objects are sharable they should be immutable
       • Keep VO thin and simple
       • Please no huge VO, a VO can contain value objects and reference to Entities




    Javaday Roma 2007               © ThoughtWorks, 2007
Javaday Roma 2007

                                TaskRecord

public class TaskRecord
{
     private readonly Reference reference;
     private readonly decimal value;
     private readonly string xml;
     private readonly User generatedBy;
     private readonly DateTime generationTime;
public TaskRecord(…)
{
    this… = …
}


     Javaday Roma 2007              © ThoughtWorks, 2007
Javaday Roma 2007

                                   Services
• In the ubiquitous language the objects are the nouns, the services are
  the verbs.
• A service provides functionality for the domain
• I can’t really put this stuff on an object!
• A service performs an operation
    – The operation refers to a domain concept
    – The operations refers to other object in the domain model
    – The operation is stateless
• Keeps the domain isolated




     Javaday Roma 2007             © ThoughtWorks, 2007
Javaday Roma 2007

                  IImageReplicationService
public interface IImageReplicationService
  {
    void Send(ISessionContext sessionContext, Image image,
  PhotoDetails photoDetails);
  }




      Javaday Roma 2007       © ThoughtWorks, 2007
Javaday Roma 2007

                      Tasks & Commands
• Not Stateless operations
• Fairly Isolated
• A Presenter uses one or more Tasks
• A Task can use one more Commands




     Javaday Roma 2007       © ThoughtWorks, 2007
Javaday Roma 2007

                        SaveUserCommand
public void Execute()
    {
        user.Username = username;
        user.IsAuthorised = isAuthorised;
        user.CardNumber = cardNumber;
        sessionContext.SaveOrUpdate(user);
    }




    Javaday Roma 2007         © ThoughtWorks, 2007
Javaday Roma 2007

                                   Modules
• In a complex system the model grows
   – Let’s split it in to modules, in order to reduce complexity
   – High level of cohesion, low level of coupling
   – Communicational cohesion
       • Parts of the module work with same data
   – Functional cohesion
       • Parts of the module work together to perform well-defined tasks




    Javaday Roma 2007              © ThoughtWorks, 2007
Javaday Roma 2007

                                 Aggregates
• Relations between objects
   – One to many, many to many, complexity!
   – First, try to remove and refactor when you don’t need it
   – Try to reduce multiplicity and direction (bi to mono)
   – Cascade on update/delete, usually the db does this for us
   – Typically then what happen? Poor performances!
   – Use aggregate
       • An aggregate has an entity as root element
       • Only the root is obtainable through queries
       • The Entity is responsible of maintaining the invariants




    Javaday Roma 2007               © ThoughtWorks, 2007
Javaday Roma 2007

                                    Factories
• When creating an objects instance is complex
• When creating an object (especially an Aggregate) is a responsibility
    – Use factories.
    – I create the root of the Aggregate and all the contained object
    – Atomic creation
    – Factories violates objects encapsulation, be careful!
    – Use a constructor when:
        • It’s simple
        • All the attributes can be passed via the constructor
        • The class is the type, there’s no need to choose different implementation




     Javaday Roma 2007               © ThoughtWorks, 2007
Javaday Roma 2007

                            IPresenterFactory
public interface IPresenterFactory
    {
IPresenter CreateTaskDetailPresenter(ITaskDetailView view,
   IAddCommentsUserAction addCommentsAction);
…
}




        Javaday Roma 2007       © ThoughtWorks, 2007
Javaday Roma 2007

                               Repositories
• We don’t want to be coupled to the DB/persistence infrastructure
    – A repository encapsulate the logic in order to obtain object references
    – It may include a Strategy
    – It should be simple (find, add for example)
• A factory creates, a repository retrieves.
• A factory is pure domain, a repository communicates with the
  infrastructure




     Javaday Roma 2007            © ThoughtWorks, 2007
Javaday Roma 2007

                          IUserRepository
public interface IUserRepository : IRepository<User>
  {
      User FindWithCardId(string cardNumber);
      ICollection<User> FindAllUsers();
      ICollection<User> FindAllActiveUsers();
      bool IsUniqueUsername(string username, User currentUser);
      bool IsValidUsername(string username);
      IList<User> GetUsersByCardId(string cardNumber);
  }




      Javaday Roma 2007        © ThoughtWorks, 2007
Javaday Roma 2007

                        All together
.




    Javaday Roma 2007    © ThoughtWorks, 2007
Javaday Roma 2007

                Domain Specific Languages
• Small, Domain focused language
• Domain experts themselves can understand, validate, modify, and often
  even develop DSL programs
• Do I really need a new language?
• Fluent interfaces




     Javaday Roma 2007        © ThoughtWorks, 2007
Javaday Roma 2007

                                                                   UserBuilder

public class UserBuilder
    {
        private string name = quot;UserBuilder generated userquot;;
        private bool isAuthorised = true;
        private readonly List<Permission> permissions = new List<Permission>();
        public UserBuilder Name(string value)
        {
             name = value;
             return this;
        }
        public UserBuilder CardNumber(string value)
        {
             cardNumber = value;
             return this;
        }
        public User ToUser()
        {
             return new User(name, cardNumber, isAuthorised, permissions.ToArray());
        }
…
            User testUser = new UserBuilder().Name(“antonio”).CardNumber(“1234”). ToUser();




                Javaday Roma 2007                                © ThoughtWorks, 2007
Javaday Roma 2007

                              Dev/BA
• Dev pair sessions with BA
• Domain Experts
• Code that “even” a BA can read and change




    Javaday Roma 2007          © ThoughtWorks, 2007
Javaday Roma 2007

                           Q&A?




                        Grazie!




    Javaday Roma 2007   © ThoughtWorks, 2007

More Related Content

Viewers also liked

Effective Strategies for Distributed Testing
Effective Strategies for Distributed TestingEffective Strategies for Distributed Testing
Effective Strategies for Distributed TestingAnand Bagmar
 
Machine learning in software testing
Machine learning in software testingMachine learning in software testing
Machine learning in software testingThoughtworks
 
Strategies for Distributed Testing
Strategies for Distributed TestingStrategies for Distributed Testing
Strategies for Distributed TestingvodQA
 
What is Agile Testing?
What is Agile Testing?What is Agile Testing?
What is Agile Testing?vodQA
 
Weather Presentation
Weather PresentationWeather Presentation
Weather Presentationbu.lauren
 
Amy&Per Erik
Amy&Per ErikAmy&Per Erik
Amy&Per Erikvinion
 
Produtos e serviços da Web 2.0
Produtos e serviços da Web 2.0Produtos e serviços da Web 2.0
Produtos e serviços da Web 2.0Elcio Ferreira
 
Lost In The Kingdom Of Vorg
Lost In The Kingdom Of VorgLost In The Kingdom Of Vorg
Lost In The Kingdom Of VorgKwan Tuck Soon
 
Souper Bowl 2005 Pictures
Souper Bowl 2005 PicturesSouper Bowl 2005 Pictures
Souper Bowl 2005 Picturesburnsc62
 
Verdaderas Obras De Arte
Verdaderas Obras De ArteVerdaderas Obras De Arte
Verdaderas Obras De Arteblackangel
 
Publizitate Eraginkortasunaren Baliospena 5
Publizitate Eraginkortasunaren Baliospena 5Publizitate Eraginkortasunaren Baliospena 5
Publizitate Eraginkortasunaren Baliospena 5katixa
 
Deforestation
DeforestationDeforestation
Deforestationkimoneill
 
Zine Teoriak2
Zine Teoriak2Zine Teoriak2
Zine Teoriak2katixa
 

Viewers also liked (20)

Effective Strategies for Distributed Testing
Effective Strategies for Distributed TestingEffective Strategies for Distributed Testing
Effective Strategies for Distributed Testing
 
Tw specifications for-testing1
Tw specifications for-testing1Tw specifications for-testing1
Tw specifications for-testing1
 
Functional testing patterns
Functional testing patternsFunctional testing patterns
Functional testing patterns
 
Machine learning in software testing
Machine learning in software testingMachine learning in software testing
Machine learning in software testing
 
Strategies for Distributed Testing
Strategies for Distributed TestingStrategies for Distributed Testing
Strategies for Distributed Testing
 
What is Agile Testing?
What is Agile Testing?What is Agile Testing?
What is Agile Testing?
 
Weather Presentation
Weather PresentationWeather Presentation
Weather Presentation
 
Amy&Per Erik
Amy&Per ErikAmy&Per Erik
Amy&Per Erik
 
Roysville
RoysvilleRoysville
Roysville
 
Produtos e serviços da Web 2.0
Produtos e serviços da Web 2.0Produtos e serviços da Web 2.0
Produtos e serviços da Web 2.0
 
Lost In The Kingdom Of Vorg
Lost In The Kingdom Of VorgLost In The Kingdom Of Vorg
Lost In The Kingdom Of Vorg
 
Souper Bowl 2005 Pictures
Souper Bowl 2005 PicturesSouper Bowl 2005 Pictures
Souper Bowl 2005 Pictures
 
独特的荷兰风车
独特的荷兰风车独特的荷兰风车
独特的荷兰风车
 
Verdaderas Obras De Arte
Verdaderas Obras De ArteVerdaderas Obras De Arte
Verdaderas Obras De Arte
 
Biz Cafe
Biz CafeBiz Cafe
Biz Cafe
 
Kazen evanjelizacia&ucenictvo-16.02.2014
Kazen evanjelizacia&ucenictvo-16.02.2014Kazen evanjelizacia&ucenictvo-16.02.2014
Kazen evanjelizacia&ucenictvo-16.02.2014
 
Artalk
ArtalkArtalk
Artalk
 
Publizitate Eraginkortasunaren Baliospena 5
Publizitate Eraginkortasunaren Baliospena 5Publizitate Eraginkortasunaren Baliospena 5
Publizitate Eraginkortasunaren Baliospena 5
 
Deforestation
DeforestationDeforestation
Deforestation
 
Zine Teoriak2
Zine Teoriak2Zine Teoriak2
Zine Teoriak2
 

Similar to Domain Driven Design Javaday Roma2007

Building a JavaScript Library
Building a JavaScript LibraryBuilding a JavaScript Library
Building a JavaScript Libraryjeresig
 
Android Bootcamp
Android   BootcampAndroid   Bootcamp
Android Bootcampahkjsdcsadc
 
Java EE Revisits GoF Design Patterns
Java EE Revisits GoF Design PatternsJava EE Revisits GoF Design Patterns
Java EE Revisits GoF Design PatternsMurat Yener
 
Smart Client Development
Smart Client DevelopmentSmart Client Development
Smart Client DevelopmentTamir Khason
 
What's new in DWR version 3
What's new in DWR version 3What's new in DWR version 3
What's new in DWR version 3Joe Walker
 
Usability in the GeoWeb
Usability in the GeoWebUsability in the GeoWeb
Usability in the GeoWebDave Bouwman
 
Project Zero For Javapolis 2007
Project Zero For Javapolis 2007Project Zero For Javapolis 2007
Project Zero For Javapolis 2007Jason McGee
 
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume LaforgeGroovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume LaforgeGuillaume Laforge
 
How to make Ajax Libraries work for you
How to make Ajax Libraries work for youHow to make Ajax Libraries work for you
How to make Ajax Libraries work for youSimon Willison
 
Rise of the Single Page Application
Rise of the Single Page ApplicationRise of the Single Page Application
Rise of the Single Page ApplicationPiyush Katariya
 
Language-Oriented Programming and Language Workbenches: Building Domain Langu...
Language-Oriented Programming and Language Workbenches: Building Domain Langu...Language-Oriented Programming and Language Workbenches: Building Domain Langu...
Language-Oriented Programming and Language Workbenches: Building Domain Langu...elliando dias
 
Javascript Framework Roundup FYB
Javascript Framework Roundup FYBJavascript Framework Roundup FYB
Javascript Framework Roundup FYBnukeevry1
 
JRuby - Enterprise 2.0
JRuby - Enterprise 2.0JRuby - Enterprise 2.0
JRuby - Enterprise 2.0Jan Sifra
 
Internship softwaretraining@ijse
Internship softwaretraining@ijseInternship softwaretraining@ijse
Internship softwaretraining@ijseJinadi Rashmika
 
J2EE vs JavaEE
J2EE vs JavaEEJ2EE vs JavaEE
J2EE vs JavaEEeanimou
 
Ajax Tutorial
Ajax TutorialAjax Tutorial
Ajax Tutorialoscon2007
 
Why Nodejs Guilin Shanghai
Why Nodejs Guilin ShanghaiWhy Nodejs Guilin Shanghai
Why Nodejs Guilin ShanghaiJackson Tian
 

Similar to Domain Driven Design Javaday Roma2007 (20)

Building a JavaScript Library
Building a JavaScript LibraryBuilding a JavaScript Library
Building a JavaScript Library
 
Android Bootcamp
Android   BootcampAndroid   Bootcamp
Android Bootcamp
 
Java EE Revisits GoF Design Patterns
Java EE Revisits GoF Design PatternsJava EE Revisits GoF Design Patterns
Java EE Revisits GoF Design Patterns
 
Smart Client Development
Smart Client DevelopmentSmart Client Development
Smart Client Development
 
What's new in DWR version 3
What's new in DWR version 3What's new in DWR version 3
What's new in DWR version 3
 
Usability in the GeoWeb
Usability in the GeoWebUsability in the GeoWeb
Usability in the GeoWeb
 
Project Zero For Javapolis 2007
Project Zero For Javapolis 2007Project Zero For Javapolis 2007
Project Zero For Javapolis 2007
 
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume LaforgeGroovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
Groovy in the Enterprise - Case Studies - TSSJS Prague 2008 - Guillaume Laforge
 
How to make Ajax Libraries work for you
How to make Ajax Libraries work for youHow to make Ajax Libraries work for you
How to make Ajax Libraries work for you
 
Ruby on Rails Presentation
Ruby on Rails PresentationRuby on Rails Presentation
Ruby on Rails Presentation
 
Rise of the Single Page Application
Rise of the Single Page ApplicationRise of the Single Page Application
Rise of the Single Page Application
 
Language-Oriented Programming and Language Workbenches: Building Domain Langu...
Language-Oriented Programming and Language Workbenches: Building Domain Langu...Language-Oriented Programming and Language Workbenches: Building Domain Langu...
Language-Oriented Programming and Language Workbenches: Building Domain Langu...
 
Javascript Framework Roundup FYB
Javascript Framework Roundup FYBJavascript Framework Roundup FYB
Javascript Framework Roundup FYB
 
JRuby - Enterprise 2.0
JRuby - Enterprise 2.0JRuby - Enterprise 2.0
JRuby - Enterprise 2.0
 
Os Haase
Os HaaseOs Haase
Os Haase
 
Internship softwaretraining@ijse
Internship softwaretraining@ijseInternship softwaretraining@ijse
Internship softwaretraining@ijse
 
J2EE vs JavaEE
J2EE vs JavaEEJ2EE vs JavaEE
J2EE vs JavaEE
 
Node azure
Node azureNode azure
Node azure
 
Ajax Tutorial
Ajax TutorialAjax Tutorial
Ajax Tutorial
 
Why Nodejs Guilin Shanghai
Why Nodejs Guilin ShanghaiWhy Nodejs Guilin Shanghai
Why Nodejs Guilin Shanghai
 

More from Antonio Terreno

More from Antonio Terreno (12)

Serverless conference-labrador-at-2018
Serverless conference-labrador-at-2018Serverless conference-labrador-at-2018
Serverless conference-labrador-at-2018
 
Blend it up - leancamp london presentation
Blend it up - leancamp london presentationBlend it up - leancamp london presentation
Blend it up - leancamp london presentation
 
Programmer Anarchy
Programmer AnarchyProgrammer Anarchy
Programmer Anarchy
 
Socket.io
Socket.ioSocket.io
Socket.io
 
Agiler without a schema @forward
Agiler without a schema @forwardAgiler without a schema @forward
Agiler without a schema @forward
 
Mongo db
Mongo dbMongo db
Mongo db
 
J2Me Il Micro Mondo Java
J2Me Il Micro Mondo JavaJ2Me Il Micro Mondo Java
J2Me Il Micro Mondo Java
 
Jc06 Antonio Terreno Fluidtime
Jc06 Antonio Terreno FluidtimeJc06 Antonio Terreno Fluidtime
Jc06 Antonio Terreno Fluidtime
 
Kommons
KommonsKommons
Kommons
 
From Amber To Green in Four Weeks
From Amber To Green in Four WeeksFrom Amber To Green in Four Weeks
From Amber To Green in Four Weeks
 
Time Boxing
Time BoxingTime Boxing
Time Boxing
 
Importance Of Being Driven
Importance Of Being DrivenImportance Of Being Driven
Importance Of Being Driven
 

Recently uploaded

Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 

Recently uploaded (20)

Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 

Domain Driven Design Javaday Roma2007

  • 1. Domain Driven Design Antonio Terreno Javaday 1 December 2007, Rome Javaday Roma 2007 © ThoughtWorks, 2007
  • 2. Javaday Roma 2007 Software design is art “Software design is an art, and like any art it cannot be taught and learned as a precise science, by means of theorems and formulas.” Floyd Marinescu Javaday Roma 2007 © ThoughtWorks, 2007
  • 3. Javaday Roma 2007 The Agile Way • No upfront design, requirement gathering • The team makes the design • Participation with the stakeholder • Simple, what is simple for you? • What is good for you? • Refactoring, refactoring how? (dev skills) • Refactoring how much? (fear) Javaday Roma 2007 © ThoughtWorks, 2007
  • 4. Javaday Roma 2007 Domain Driven Development • Focus on the domain • A common language • Layered architecture • Entities / Value Objects • Services • Modules • Aggregates • Factories • Repositories Javaday Roma 2007 © ThoughtWorks, 2007
  • 5. Javaday Roma 2007 Domain Driven • Layered architecture – User interface – Application Layer • No business logic • No State of business objects • Holds state of an application task progress – Domain Layer • Info about the domain • State is held here – Infrastructure Layer • Communication between layers • Persistence for business objects • Support libraries Javaday Roma 2007 © ThoughtWorks, 2007
  • 6. Javaday Roma 2007 Why layers? • Manage changes • Avoids coupling of code • Avoids unexpected behaviors after changes Javaday Roma 2007 © ThoughtWorks, 2007
  • 7. Javaday Roma 2007 Entities • Objects that have an identity • Spanning the life of the system and even after • a Person object for example • The Id does never change • Some domain objects have already the concept of id – National number, airport code, … • All the domain objects are then entities? Javaday Roma 2007 © ThoughtWorks, 2007
  • 8. Javaday Roma 2007 User public class User { private string name; private bool isAuthorised; private readonly IList myPermissions = new List<Permission>(); protected Guid id; public User(string name, bool isAuthorised, params Permission[] permissions) { id = Guid.Empty; this.name = name; this.isAuthorised = isAuthorised; SetPermissions(permissions); } Javaday Roma 2007 © ThoughtWorks, 2007
  • 9. Javaday Roma 2007 Value Objects • When we care about what an object has and not about which object is – How and when write a VO? • First we write a VO when the object is NOT an Entity! • Will be great if a VO is immutable • For performance but mostly • They will manifest integrity • If value objects are sharable they should be immutable • Keep VO thin and simple • Please no huge VO, a VO can contain value objects and reference to Entities Javaday Roma 2007 © ThoughtWorks, 2007
  • 10. Javaday Roma 2007 TaskRecord public class TaskRecord { private readonly Reference reference; private readonly decimal value; private readonly string xml; private readonly User generatedBy; private readonly DateTime generationTime; public TaskRecord(…) { this… = … } Javaday Roma 2007 © ThoughtWorks, 2007
  • 11. Javaday Roma 2007 Services • In the ubiquitous language the objects are the nouns, the services are the verbs. • A service provides functionality for the domain • I can’t really put this stuff on an object! • A service performs an operation – The operation refers to a domain concept – The operations refers to other object in the domain model – The operation is stateless • Keeps the domain isolated Javaday Roma 2007 © ThoughtWorks, 2007
  • 12. Javaday Roma 2007 IImageReplicationService public interface IImageReplicationService { void Send(ISessionContext sessionContext, Image image, PhotoDetails photoDetails); } Javaday Roma 2007 © ThoughtWorks, 2007
  • 13. Javaday Roma 2007 Tasks & Commands • Not Stateless operations • Fairly Isolated • A Presenter uses one or more Tasks • A Task can use one more Commands Javaday Roma 2007 © ThoughtWorks, 2007
  • 14. Javaday Roma 2007 SaveUserCommand public void Execute() { user.Username = username; user.IsAuthorised = isAuthorised; user.CardNumber = cardNumber; sessionContext.SaveOrUpdate(user); } Javaday Roma 2007 © ThoughtWorks, 2007
  • 15. Javaday Roma 2007 Modules • In a complex system the model grows – Let’s split it in to modules, in order to reduce complexity – High level of cohesion, low level of coupling – Communicational cohesion • Parts of the module work with same data – Functional cohesion • Parts of the module work together to perform well-defined tasks Javaday Roma 2007 © ThoughtWorks, 2007
  • 16. Javaday Roma 2007 Aggregates • Relations between objects – One to many, many to many, complexity! – First, try to remove and refactor when you don’t need it – Try to reduce multiplicity and direction (bi to mono) – Cascade on update/delete, usually the db does this for us – Typically then what happen? Poor performances! – Use aggregate • An aggregate has an entity as root element • Only the root is obtainable through queries • The Entity is responsible of maintaining the invariants Javaday Roma 2007 © ThoughtWorks, 2007
  • 17. Javaday Roma 2007 Factories • When creating an objects instance is complex • When creating an object (especially an Aggregate) is a responsibility – Use factories. – I create the root of the Aggregate and all the contained object – Atomic creation – Factories violates objects encapsulation, be careful! – Use a constructor when: • It’s simple • All the attributes can be passed via the constructor • The class is the type, there’s no need to choose different implementation Javaday Roma 2007 © ThoughtWorks, 2007
  • 18. Javaday Roma 2007 IPresenterFactory public interface IPresenterFactory { IPresenter CreateTaskDetailPresenter(ITaskDetailView view, IAddCommentsUserAction addCommentsAction); … } Javaday Roma 2007 © ThoughtWorks, 2007
  • 19. Javaday Roma 2007 Repositories • We don’t want to be coupled to the DB/persistence infrastructure – A repository encapsulate the logic in order to obtain object references – It may include a Strategy – It should be simple (find, add for example) • A factory creates, a repository retrieves. • A factory is pure domain, a repository communicates with the infrastructure Javaday Roma 2007 © ThoughtWorks, 2007
  • 20. Javaday Roma 2007 IUserRepository public interface IUserRepository : IRepository<User> { User FindWithCardId(string cardNumber); ICollection<User> FindAllUsers(); ICollection<User> FindAllActiveUsers(); bool IsUniqueUsername(string username, User currentUser); bool IsValidUsername(string username); IList<User> GetUsersByCardId(string cardNumber); } Javaday Roma 2007 © ThoughtWorks, 2007
  • 21. Javaday Roma 2007 All together . Javaday Roma 2007 © ThoughtWorks, 2007
  • 22. Javaday Roma 2007 Domain Specific Languages • Small, Domain focused language • Domain experts themselves can understand, validate, modify, and often even develop DSL programs • Do I really need a new language? • Fluent interfaces Javaday Roma 2007 © ThoughtWorks, 2007
  • 23. Javaday Roma 2007 UserBuilder public class UserBuilder { private string name = quot;UserBuilder generated userquot;; private bool isAuthorised = true; private readonly List<Permission> permissions = new List<Permission>(); public UserBuilder Name(string value) { name = value; return this; } public UserBuilder CardNumber(string value) { cardNumber = value; return this; } public User ToUser() { return new User(name, cardNumber, isAuthorised, permissions.ToArray()); } … User testUser = new UserBuilder().Name(“antonio”).CardNumber(“1234”). ToUser(); Javaday Roma 2007 © ThoughtWorks, 2007
  • 24. Javaday Roma 2007 Dev/BA • Dev pair sessions with BA • Domain Experts • Code that “even” a BA can read and change Javaday Roma 2007 © ThoughtWorks, 2007
  • 25. Javaday Roma 2007 Q&A? Grazie! Javaday Roma 2007 © ThoughtWorks, 2007