domain driven design - garajco education 2017

42
Domain Driven Design Handling complex business logic an Pekdemir 12.01.2017

Upload: can-pekdemir

Post on 08-Feb-2017

297 views

Category:

Software


0 download

TRANSCRIPT

Domain Driven Design Handl ing complex bus iness log ic

Can Pekdemi r

12.01.2017

Agenda• Domain Driven Design and the Motivation Behind• Maintaining Model Integrity• Expressing the Model• Lifecycle of Domain Objects

3

The Term

• Domain Driven Design: Tackling Complexity in the Heart of Software,

Eric Evans, 2003

4

In the Beginning of a Product

Two Major Drawbacks

Growing Complexity

Time to Market

8

What is Domain Driven Design?

• An approach to software development for solving complex business problems.

• A mindset of developing business not only software

• A set of patterns, principles and practices

9

The Motivation Behind DDD

• Focusing on core domain

• Helping enterprise architecture and organization

• Coping with technology challenges(Enterprise frameworks, NoSQL, Microservices)

10

Conway’s Law

“Organizations which design systems are constrained to produce designs which are copies of the communication structures of these organizations.”

— Mel Conway

11

Exploring the Domain with Collaboration

12

Ubiquitous Language

• One team, one language

• No need for translation

• Use in both communication and in the code

13

Analysis and Code Model Separate

14

Analysis and Code Model Together

15

Hands-on Modelers

• “People who write the code

should feel responsible for the model.”

• “A modeler should not be separated

from implementation.”

16

Domain Driven Design Problem SpaceTwo techniques;- Whirlpool- Event Storming

17

Big Ball of Mud

18

Big Ball of Mud

19

Distillation

20

Real Numbers• Over 6000 employees• In 400 cities and 70 countries• From 200 engineers to 2000 Engineers only in a year and half• 8000 git repositories• Over 1000 microservices

https://www.youtube.com/watch?v=kb-m2fasdDYWhat I Wish I Had Known Before Scaling Uber to 1000 Services - Matt Ranney“Scaling the traffic is not the issue. Scaling the team and the product feature release rate is the primary driver.”

21

Bounded Context• Classical divide-and-conquer strategy

• Divide large system into autonomous contexts

• Be explicit about the context responsibilites

• Each should have a refined model and a ubiquitous language

• Explicitly set boundaries and

relationships with each other

• Care about team organization, code bases, database schemas

22

Context Map• Strategic domain driven design• Very useful tool to understand overall architecture and relationships

of the system.

23

Preserving Model Integrity

24

Isolating the Domain

25

Isolation the Domain in Bounded Contexts

26

Expressing the Model

• Entities

• Value Objects

• Domain Services

27

Entity

• “Many objects are not fundamentally defined by their attributes, but rather by a thread of continuity and identity. ”

• But, Identity is not always an ID.

• Anemic vs. Rich-Behaviour Domain Model

28

Value Objects

• Have no conceptual identity, defined by their attributes

• Should be immutable

29

Domain Services

• Reflect business processes

• Mainly uses more than one entity or value object

• Should be stateless

• e.g. transferMoney

30

Lifecycle of Domain Objects

• Aggregates

• Factories

• Repositories

31

Aggregates• Mark one entity as root

• Contains other entities and value objects

• Apply consistency boundaries with aggregates and enforces invariants.

• External objects should not access child entity of Aggregate directly. All access operations should be done over the root

• Beginner for microservices

32

Aggregates

33

Aggregates

34

How to Decide Aggregate Root

• Which entities exist in most operations?

• Cascading delete is okay?

35

Factories

36

Factory Sample

37

Repositories

38

Repository - Sample

39

Making Implicit Concepts Explicit – Specification Pattern

40

Recap• Focus on your domain

• Be explicit about your bounded contexts

• Use context map and be aware of the big picture

• Code should reveal business

41

Resources• Books

• Linkshttp://www.clipartkid.com/ubiquitous-language-cliparts/ https://morecoding.wordpress.com/2015/01/03/n-tier-architecture/ https://tommcfarlin.com/wp-content/uploads/2014/08/big-ball-of-mud.jpghttp://howtodoinjava.com/design-patterns/creational/implementing-factory-design-pattern-in-java/

thanks12.01.2017