Upgrade to Pro — share decks privately, control downloads, hide ads and more …

A DDD-traineeship at "Cary's Cars" at DDDNL

A DDD-traineeship at "Cary's Cars" at DDDNL

TL,DR; Join this months Meetup to gain experience with modeling your domain in code, by working on a real problem.

# The Domain-Driven Design experience-paradox

Did you recently learn about Domain-Driven Design, and are you excited about the potential to express domain-knowledge in code? Do you get inspired when reading sample code that showcases how capable a rich domain model may become?
Eventually your initial optimism about DDD will be superseded by a difficult question:

> How would I achieve such a rich design for my own domain?

Turning a model into a well functioning design can be quite a daunting task, especially when you lack practical experience. When you get started you may quickly find yourself asking various questions:

Where do I start?

- When should I apply the tactical patterns in my design?
- How should I discuss and evaluate design trade-offs with other people?
- When should I sacrifice purity of the model and the design for progress?
- How do I apply a specific tactical pattern in my programming language of choice?
- Am I doing it right?

There is good news, practice makes perfect. As you gain more experience you will learn to focus on the domain itself, and worry less about doing things according to the book. You will know to judge a model by its usefulness. As such, the best shortcut is to get your hands dirty: wax-on, wax-off. Challenge yourself to model small problems to hone the skills required.

Unfortunately you cannot gain experience in applying Domain-Driven Design without putting thought into the domain itself. Sure, you could get started with the tactical design patterns to create a blog, a user-management system, a CRM, or a todo list, but without the capriciousness of a real domain and a real project you'd be fooling yourself. You need something smaller and you need something more relatable to your day-to-day work.

## A DDD-traineeship at Cary Cars

Imagine you recently joined 'Cary Cars', a car sharing service that started operating in Amsterdam 6 months ago. Cary Cars operates 300 vehicles that are spread out over the compact city center. Owning and operating a car is expensive and Cary Cars is on a mission to make car ownership a thing of the past.
In this workshop you will model and design Cary Cars pricing engine. In doing so you will:

- Get coding quickly in a pre-setup project
- Experience the benefits of Value Objects
- Leverage testing as a tool to discover design details
- Evolve the model and design as new requirements come in
- Contrast different implementation choices with other participants
- Learn about the trade-offs of the programming language of your choice

## The workshop program

Homework prior to the workshop:

- Install the sample project
- Familiarize yourself with the domain
- Research implementation styles in your programming language
- Evolve the model with new aspects relevant to pricing

During the workshop:

- Compare your work with that of another participant
- Pair-program on additional functionality
- Visualize the model using various techniques
- Discuss trade-offs with other participants

## Should you attend this workshop?

Regardless if you are eager to learn DDD or if you are hesitant towards it due to your personal beliefs, the best way to evaluate something is to try it.
Have you gained some practical experience with DDD already? A wide variety of Domain-modeling approaches exists. It is unlikely you are equally proficient in all of them, this session is an ideal playground to experiment with less familiar styles. As a courtesy to your fellow attendees, do make sure that you come prepared in case you decide to join.

## How it works

After signing up for the workshop you will receive an email with instructions for the homework. You will submit your homework to a GitHub repository. During the workshop you will pair program in break-out groups on-site. Modeling activities will take place in a shared Miro board.

## Prerequisites

Make sure that you are able to:

- Use an IDE for automated refactoring
- Write a test in the programming language of choice
- Run tests from your IDE
- Commit and push code to a private GitHub account
- Collaborate using your own Miro account or using a whiteboard on-site

Marijn Huizendveld

March 23, 2023
Tweet

More Decks by Marijn Huizendveld

Other Decks in Business

Transcript

  1. @huizendveld @DDDNederland Modeling in Code Carries Cars DDD Traineeship The

    goal of this workshop is to experiment with di ff erent approaches to building software. The workshop lasts until circa 21:00. The domain for this workshop: Car- sharing in population dense cities Learning is serious business, but let's agree to not take ourselves too serious. Fun is an important ingredient of good work. Mar i jn
  2. @huizendveld @DDDNederland Did you do the homework? You will get

    started right away, form teams with another attendee (if you did not do the homework team up with someone that also did not do it). Take 20 minutes to compare your homework to that of your partner: 1. Are the tests passing? 
 2. What 3 things does your partner like about the example project? 
 3. What questions does your partner still have? Were you unable to do the homework? You and your fellow trainee will take the time to set-up the project. Sca n to a c c e s s the ho m ew o r k e xe r cis e https://marijn.huizendveld.com/workshops/carries-cars-ddd-traineeship
  3. Sho ut o u t ! 
 
 Wha t

    di d yo u lea r n f r o m l ook i n g at t h e w o r k yo ur co l lea gu e did ?
  4. @huizendveld @DDDNederland A domain model is… ✔︎ 🎼 A set

    of abstractions ✔︎ 🗺 A simpli fi cation ✔︎ 🗄 A way to organize the messiness of reality ✔︎ 🔥 A way to solve a speci fi c problem ✔︎ 📋 NOT a precise copy of reality
  5. Dom ai n Co m p l exi t y

    Tec hni c al Co m p lexi t y Tic ket S a le + re s er v e Ti cke t() Cap a cit y + in crea se() + de crea se() Eve nt D e t a i ls + re s c h edul e() Pri cin g + o ffe rP rom ot ion () My Sq l D at a bas e Con nec t i o n D e t a il s Dat abas eSc hem a Dat abas eTr ans a c t i on
  6. Ap pl ic ati o n Dom ai n Mo

    d e l For example with the layered architecture • The goal is to isolate the domain model • Only introduce coupling to lower layers • Focus the design to express complexity in the domain • See Domain-Driven Design Reference page 10 U I In fr as tru c tur e
  7. @huizendveld @DDDNederland Forget everything you know of the tactical part

    of DDD If y o u ar e a l re a d y aw ar e o f s o me pa t te r ns
  8. Red Gre en Ref acto r Im pl em e

    nt i n a n aiv e wa y Ref acto r u nti l re ason ab l e Wri t e a fa ili n g t e x t Com m i t e ac h s t e p , ho weve r s m al l i t i s!
  9. @huizendveld @DDDNederland Implicit concepts at Cary’s Cars 🔍 Identify implicit

    concepts with your partner ✍ Write them down on paper or on your device 5 mi n . 5 minutes
  10. In v o ic e In v o ic e

    Num b e r Giv e e v e r y c on c ept in your mo d e l a re pr e s ent at ion i n c o de . Co u l d be a fu nc t ion , a c o ns t ant , an inte r f a ce , a t yp e, a m e t ho d, et c …
  11. @Test public void Multiplies_with_Duration() { PricePerMinute pricePerMinute = new PricePerMinute(Money.of(CurrencyUnit.EUR,

    0.24)); Duration someDuration = new Duration(8); Money actual = pricePerMinute.calculateMinutePrice(someDuration); Money expected = Money.of(CurrencyUnit.EUR, 1.92); assertEquals(expected, actual); }
  12. final class PricePerMinute { public Money calculateMinutePrice(Duration someDuration) { return

    pricePerMinute.multipliedBy(someDuration.durationInMinutes()); } // Boring code below private Money pricePerMinute; public PricePerMinute(Money pricePerMinute) { this.pricePerMinute = pricePerMinute; } }
  13. @huizendveld @DDDNederland Continue work on the next exercises 🏃 Work

    at your own pace, you don’t have to fi nish all exercises in order to learn something 🛋 Step out of your comfort zone to learn 👂 Pay attention to the input of your partner 20 mi n .
  14. @Test public void Two_prices_are_identical_if_the_rate_is_identical() { PricePerMinute pricePerMinute = new PricePerMinute(

    Money.of(CurrencyUnit.EUR, 0.24) ); PricePerMinute identicalPricePerMinute = new PricePerMinute( Money.of(CurrencyUnit.EUR, 0.24) ); assertEquals(pricePerMinute, identicalPricePerMinute); }
  15. static public function provide_time_that_is_incomplete () { return [ 'without hour'

    => [ 'time' => ' : 59', ], 'without minute' => [ 'time' => '12 : ', ], 'without seperator' => [ ‘time' => '1259', ] ]; }
  16. @huizendveld @DDDNederland Continue work on the next exercises 🏃 Work

    at your own pace, you don’t have to fi nish all exercises in order to learn something 🛋 Step out of your comfort zone to learn 👂 Pay attention to the input of your partner 20 mi n .
  17. @huizendveld @DDDNederland Make a checklist that helps you the next

    time you are modeling in code ✅ What are important things to remember when you are modeling in code? 💭 What are tricks to get unstuck? ↕ Which lessons are most valuable to you? 5 mi n .
  18. Eager to learn more? ✉ [email protected] 🖥 https://marijn.huizendveld.com Anthony Fokkerweg

    3 - 1059 CM Amsterdam - The Netherlands Reach out for links to additional reference material and any questions you may have.