Latest and trendiest? A template in Visual Studio? The best best practice? No! Much better! I...

Preview:

Citation preview

Developing core-business applications with DDDJimmy Nilsson, factor10

DEV-B311

About meDeveloper/architectjimmynilsson.com/blog

Twitter: @JimmyNilsson

Author”Applying Domain-Driven Design and Patterns” and”.NET Enterprise Design”

CompanyCo-founder and CEO for factor10

Context

Exponential effect!

Dare to challenge!TDomain-Driven Design (DDD)

How we as humans/developers are

Why Domain-Driven Design?Latest and trendiest?A template in Visual Studio?The best best practice?

No! Much better!

I believe that DDD can help very much in creating business value.

What is software development all about? $Why?

What?

How?

”Code!”

? ? ? And so on…

$

Basic software economics

Complexity

Productivity

Question is, is it essential complexity or accidental complexity?

Not just code in control

...the size is of tremendous importance!

The size…- drives cost- drives bugs- drives delays- drives team size, which drives code size…

What is Domain-Driven Design?Domain-Driven Design is an approach to the

development of complex software in which we:

• Focus on the core domain

• Explore models in a creative collaboration of domain practitioners and software practitioners

• Speak a ubiquitous language within an explicitly bounded context

http://domainlanguage.com/ddd/patterns/DDD_Reference_2011-01-31.pdf

Problem and chosen solution

Model

UmlAsASketch

UbiquitousLanguage Code

Model, code, etc... How do they fit together?

UI

Demo

Ubiquitous language and bounded context

Argh! Why not come up

with ten more words

for describing the same thing…

Why on Earth does

he care about that?

It’s just words…

Ubiquitous language with Behavior-Driven Development (BDD)As an insurance brokerI want to know who my gold customers areSo that I sell more

Given customer Sven Svensson existsWhen he buys insurance XYZ for 10000 USDThen he becomes a gold customer

Demo

Learning and collaborating

Sigh, he’s coming with that now!?

Sigh, he’s coming with that now!?

A comparison between domain-driven design and database-driven design, a few simple examples

”Customers have rentals”Customer Rental

Some typical T-SQL...IF (SELECT COUNT(*) FROM RentalLines

INNER JOIN Products ON RentalLines.ProductId = Products.Id WHERE RentalId = inserted.Id AND RequiredAge > @ageOfCustomer) > 0 BEGIN

ROLLBACK RAISERROR... RETURN

END

UPDATE Rentals SET Status = 4 WHERE Id = inserted.IdAND Status = 3SELECT @anError = @@ERROR, @aRowCount = @@ROWCOUNT

...

Another approach, first try...public bool CanCheckOut(){ if (status != RentalStatus.New) return false;

if (Customer.Age < highestRequiredAgeOfAnyOfTheChosenFilms())

return false;

return true;} public void CheckOut(){ if (! CanCheckOut()) throw new...

...

status = RentalStatus.CheckedOut;}

Transaction Script vs Domain Model

vs

If I can only talk about one tactical pattern…

Value Objects

Like this?var stinasEggs = 7 * 12;

var pellesEggs = 3 * 20;

var theNumberOfEggsInTheBasket = stinasEggs + pellesEggs;

Assert.AreEqual(144, theNumberOfEggsInTheBasket);

Or like this?var stinasEggs = Amount.Dozen(7);

var pellesEggs = Amount.Score(3);

var theNumberOfEggsInTheBasket = stinasEggs + pellesEggs;

Assert.AreEqual(144, theNumberOfEggsInTheBasket.Count);

Architectural styles for implementing DDD

Classic layering (n-tier)

UI Facade EntitiesData

AccessTables

Most often very little focus

Traveling recordsets...

Starting point now for layering

UI Domain Model

Relaxed focus on layering, more focus on……bounded contexts!

With application databases instead of integration databasesAnd balancing loose coupling and high cohesion

Maybe you now believe you can benefit from DDD... Now what?

What follows is definitely not a prescriptive guidance...

…just an example!

Demo

“Process”

Time report…

“Process” or more like a typical flowA little strategic design

A story and scenarioUI sketchingSome UmlAsASketchTransform the scenario into an acceptance test

Test drive the needed pieces

Next story, and so on...

SummaryChallenge

Domain-Driven Design

Related contentAll the presentations at this track:Cesar de la Torre: Positioning Microsoft Development Technologies for Custom Application Development (DEV-B204)Per Rovegård: Real Experience and Architectural DDD Patterns Applied on .NET (DEV-B343)Julie Lerman: Entity Framework in Core Business Applications and DDD Approaches (DEV-B336)Greg Young: .NET Event Driven Applications, CQRS and Event Sourcing in Mission-Critical Applications (DEV-B401)Miguel Castro: Understanding Dependency Injection and Those Pesky Containers (DEV-B207)BooksEric Evans: Domain-Driven DesignJimmy Nilsson: Applying Domain-Driven Design and PatternsVaughn Vernon: Implementing Domain-Driven Design

Find Me Later At this trackor at jimmy.nilsson@factor10.com

msdn

Resources for Developers

http://microsoft.com/msdn

Learning

Microsoft Certification & Training Resources

www.microsoft.com/learning

TechNet

Resources

Sessions on Demand

http://channel9.msdn.com/Events/TechEd

Resources for IT Professionals

http://microsoft.com/technet

Complete an evaluation on CommNet and enter to win!

Evaluate this session

Scan this QR code to evaluate this session and be automatically entered in a drawing to win a prize

© 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Recommended