Coder Social home page Coder Social logo

ddd-exercise's Introduction

DDD Exercises

Exercise 1 -- Modelling the Simple Store

A simple domain keeping track of: customers, products, and orders.

TO-DO

  1. Read informal domain description
  2. Identify the main domain concepts composing the ubiquitous language
  3. Model the domain as Java types (classes or interfaces)
    • the model should include entities, value objects, repositories, factories, and services
  4. Structure the Java types according to some module structure compliant with hexagonal architecture
    • i.e. put interfaces in either the domain or the application module
  5. Sketch tests and, then, implementation for at least one
    • entity
    • value object
    • factory
    • repository
    • value object

Domain description

Customers

  • Customers can either be companies or persons

  • Companies are identified by a VAT number

  • Persons are identified by tax codes

  • In any case a name and email are recorded for each customer

  • Both the name and email may vary over time

Products

  • Products are identified by name and type/category

  • They have a nominal price, expressed using some currency

  • The availability of each product is tracked as well

  • Both the price and the available quantity may vary over time

Money and exchange rates

  • Money is represented by a decimal value and a currency

  • Currencies are represented by a name, a symbol and an acronym

    • e.g. Euro, EUR, โ‚ฌ
    • e.g. USA Dollar, USD, $
  • Exchange rates keep track of the conversion rate

    • from a source currency
    • to a destination currency
    • in a particular moment
  • Information about exchange rates can be attained from the Internet

  • We can compute the price of each product, in any currency, at any moment

Orders

  • Orders are identified by a serial number

  • They keep track of the many products ordered by a customer

    • and the amount of copies ordered for each product
  • Also, orders keep track of when they have been performed

  • All such information may be modified before the order is delivered

  • When a new order is registered, many actions should be performed in reaction

  • It must be possible to compute the actual total price of an order

    • in a particular moment, using a particular currency

Exercise 2 -- Trivial CQRS

A very simple repository: the Counter. It contains 1 long number, initially set to 0. The value may change arbitrarily. Whenever the value changes, a new domain event is published, of type Variation. However, the repository only memorise the current value of the counter.

TODO

  1. Switch the design towards event sourcing, by memorising variations instead of snapshots.
  2. Implement the CQRS pattern

In practice:

  1. provide implementations for the CounterReader and CounterWriter interfaces
  2. optionally, test those implementations

Exercise 3 -- Anti corruption layer

A very simple domain: Tables, i.e. 2-D containers of Rows, where each row contains one or more String values. Functionalities for CSV import/export are missing and need to be implemented via third-party libraries. At least two libraries are available:

TODO

  1. Extend the model of our domain with new interfaces supporting CSV parsing / writing functionalities
  2. Design the interfaces so that they are agnostic of the third-party libraries
    • without corrupting the domain model with library-specific types
  3. Provide implementations for the interfaces, using one of the two libraries
  4. Sketch tests for the implementations
  5. Provide implementations for the interfaces, using the other library
  6. Use the same tests as above to prove the two implementations work the same way

ddd-exercise's People

Contributors

gciatto avatar

Stargazers

Lorenzo Massone avatar

Watchers

Danilo Pianini avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.