46
1 DDD blog.fratech.net DDD Domain Driven Design - The way back to OO! Felipe Rodrigues de Almeida

Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

  • Upload
    dothuy

  • View
    214

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

1DDD blog.fratech.net

DDDDomain Driven Design - The way back to OO!

Felipe Rodrigues de Almeida

Page 2: Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

2DDD blog.fratech.net

The ProblemWhere are we missing the way? 3

The CoNCePTWhat is DDD about? 4Why use DDD? 6Where are we missing the way? (Fixes) 8Layered Architecture 14

The way baCkDomain Objects 19Entities, Services, Value Objects and Modules 21Objects Life-Cycle 26

The meaNiNgMeaning What? 30Ubiquitous Language 31Supple Design 32Strategic Design 34

ToPiCS

Page 3: Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

3DDD blog.fratech.net

The Problem

where are we missing the way?

What is important? What is urgent?•

Domain Models vs Manager Models (MOP)•

Bad Communication•

Architects thinking only about infra-structure•

We have lost real Object Orientation•

Page 4: Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

4DDD blog.fratech.net

The CoNCePT

what is DDD about?

Domain means “a sphere of knowledge, influency and activity “ of a situation

So, Domain Driven Design means, design (a software) driven (oriented) by it knowledge, influency and activity

Page 5: Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

5DDD blog.fratech.net

The CoNCePT

what is DDD about?

Above all, DDD is about to take the domain (a sphere of knowledge, influency and activity) and represent it in objects

DDD is the way back to OO!!!

Page 6: Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

6DDD blog.fratech.net

The CoNCePT

why to use DDD?

More than just a concept, DDD is a process to find out how to build a system and also to define how to treat specific business issues

Page 7: Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

7DDD blog.fratech.net

The CoNCePT

why to use DDD?

Using DDD as a process you will be able to:

really use all those things your teacher said you could when you •were learning OO avoid the Manager(Service) Model (MOP), which requires knowledge •about a specific implementation This kind o design is composed only by services improve the comunication between your team and the customer •

Page 8: Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

8DDD blog.fratech.net

The CoNCePT

where are we missing the way? (Fixes)

What is important? What is urgent?•The business is important and the customer too Let`s give some attention to business and customer comunication!

Important aspects cannot be left behind.

Page 9: Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

9DDD blog.fratech.net

The CoNCePT

where are we missing the way? (Fixes)

Domain Models vs Manager Models(services) MOP•Domain Models treat the business like objects, services and compositions, concerned about the way things are connected in the real world

Developing software is not about creating makers.

Page 10: Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

10DDD blog.fratech.net

The CoNCePT

where are we missing the way? (Fixes)

Bad Comunication•

The words you use when you are trying to explain a situation to your customer, who doesn’t know the system, are responsible for misunderstanding Talking with him using his business terms, will make for better communication

Use the customers words to communicate!

Page 11: Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

11DDD blog.fratech.net

The CoNCePT

where are we missing the way? (Fixes)

Architects thinking only about infra-structure•

Architects are “freak“ people that usually think about technical stuff and forget what is important to the customer

We have to think about business too.

Using DDD design will focus on business situations The internal transfer of knowledge is easier since communication will be improved as well

Page 12: Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

12DDD blog.fratech.net

The CoNCePT

where are we missing the way? (Fixes)

We have lost real Object Orientation•

Object orientation is about the use of objects and their interactions to design software

At design time, we have to find objects from the real world, to use for the specific case.

Each domain model is singular and is not applicable to another model.

Page 13: Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

13DDD blog.fratech.net

The meaNiNg

wait a minute!You said: “Each domain model is singular and is not applicable to another model.”

If I am in an enterprise, why should I have more than 1 model to describe a single “thing”, perhaps even more that 1 model per application As a proponent of DRY, this doesn’t make sense to me

Page 14: Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

14DDD blog.fratech.net

The CoNCePT

layered architectureA layered architecture at heart, is a way to separate concerns

Domain model depends on some infrastructure, but not on a specific impementation.

Page 15: Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

15DDD blog.fratech.net

The CoNCePT

Presentation layerResponsible for interacting with the user, getting information from the user and showing information to the user

The presentation layer usually depends on the application

layer or Data Source Layer!

Page 16: Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

16DDD blog.fratech.net

The CoNCePT

application layerWorks as delivery, coordinating tasks which the system is responsible for doing This layer has no business rules and is only responsible for delegating work to domain objects Its objects do not have state to reflect business situation, but can have state of a task’ s progress

Consists of a set of decorators, delegating calls to domain

layer.

Page 17: Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

17DDD blog.fratech.net

The CoNCePT

Data Source layerA set of generic technical capabilities, providing support for higher layers

Here goes the most technical things!

Page 18: Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

18DDD blog.fratech.net

The CoNCePT

Domain layerRepresents the concepts of business information and business situation

A set of generic technical capabilities, providing support for higher layers

This layer is the heart of business software!

Page 19: Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

19DDD blog.fratech.net

Domain objectsDomain Objects are instances of real entities which hold any knowledgenemt, influency or activity of a situation

We can figure out which domain objects we need, by talking to domain experts

Focusing on key words will help to define domain objects.

The way baCk

Page 20: Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

20DDD blog.fratech.net

The way baCk

Domain objects

Page 21: Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

21DDD blog.fratech.net

The way baCk

entitiesAny object which has an identity Usually is mapped to real world objects

Unique set of data.

Page 22: Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

22DDD blog.fratech.net

The way baCk

Value objectsUsed to describe characteristic of things It is part of the domain as much as entities, but is always under some model element, since it has no identity

Set of data without identity.

Page 23: Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

23DDD blog.fratech.net

The way baCk

ServicesServices are a standalone interface, which holds operations that don’t fit in any object in the model

It is not a thing, but a set of operations.

Page 24: Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

24DDD blog.fratech.net

The meaNiNg

wait a minute!You’ve said earlier that DDD is better than service/manager models, but here you’re saying that DDD uses services Make sure that you describe how this type of service is different from the other

Page 25: Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

25DDD blog.fratech.net

The way baCk

modulesOrganize your domain objects by modules, then whenever you need anything you know where it is

Don’t drive your modules by infrastrucure.

Page 26: Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

26DDD blog.fratech.net

The way baCk

objects life CycleOnce you have decided the main objects of your system, you then know about its life cyle How will it interact in the model? Who is able to use it?

Aggregate, Factory and Repository patterns stand for objects life cycle

The point is avoid showing internal complexity to the

client.

Page 27: Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

27DDD blog.fratech.net

The way baCk

aggregatesA set of objects with a unique interface for external calls Indicated for cases where you need keep consistent a set of objects

Aggregates always have a root responsible for being the

interface for others elements.

Page 28: Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

28DDD blog.fratech.net

The way baCk

FactoriesResponsible for creation of domain objects or even an entire aggregate

Required only when creation becomes too complicated.

Page 29: Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

29DDD blog.fratech.net

The way baCk

repositoriesWorks as a “repository“ for domain objects Provides a simple interface for complex persistence operations Can encapsulate several data sources for a object

Make a repository whenever you find a type that needs

global access.

Page 30: Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

30DDD blog.fratech.net

The meaNiNg

meaning what?All software has a meaning Modeling is about find the meaning of software

Find the meaning, express it and you will have a great

model.

Page 31: Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

31DDD blog.fratech.net

The meaNiNg

Ubiquitous languageCreated by the team, maintained by the team and for the team Ubiquitous Language has to be concerned about the business in question

Works like a dictionary, composed by the terms taken

from Domain Experts.

Page 32: Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

32DDD blog.fratech.net

The meaNiNg

Supple DesignCreated by the team, mainteined by the team and for the team Have to concern about the business in question

A set of concepts to make a flexible design.

Page 33: Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

33DDD blog.fratech.net

The meaNiNg

Supple Design - Some PatternsIntention-Revealing Interfaces x

Standalone Classes x

Conceptual Contours x

Page 34: Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

34DDD blog.fratech.net

The meaNiNg

Strategic DesignA set of good pratices to achieve a good Domain Model These patterns can works as a check list to improve the design quality

If you want you can express these patterns as documents.

Page 35: Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

35DDD blog.fratech.net

Strategic Design

The meaNiNg

Page 36: Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

36DDD blog.fratech.net

Strategic Design

The meaNiNg

Page 37: Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

37DDD blog.fratech.net

Strategic Design

The meaNiNg

Page 38: Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

38DDD blog.fratech.net

Strategic Design

The meaNiNg

Page 39: Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

39DDD blog.fratech.net

Strategic Design

The meaNiNg

Page 40: Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

40DDD blog.fratech.net

Strategic Design

The meaNiNg

Page 41: Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

41DDD blog.fratech.net

Strategic Design

The meaNiNg

Page 42: Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

42DDD blog.fratech.net

Strategic Design

The meaNiNg

Page 43: Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

43DDD blog.fratech.net

The meaNiNg

wait a minute!Have you considered making a connection between “Published Language” and DSLs? I forgot about this aspect, but using DDD is a fantastic way to have an architecture that can transform into a DSL via this route

Page 44: Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

44DDD blog.fratech.net

Strategic Design

The meaNiNg

Page 45: Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

45DDD blog.fratech.net

* The “Wait a minute!” questions are real questions from Ian Roughley after review this document. Thank you Ian!

** No, that man is not Ian.

waiT a miNUTe!

Page 46: Felipe Rodrigues de Almeida - jaoo.dkjaoo.dk/dl/qcon-london-2008/.../FelipeRodrigues_DDDTheWayBackToOO.pdf · Felipe Rodrigues de Almeida. ... Domain Driven Design means, design (a

46DDD blog.fratech.net

The eND

obrigado!

Felipe Rodrigues de Almeida

felipe@fratech net

blog fratech net