GithubHelp home page GithubHelp logo

ddd's Introduction

DDD Building Blocks

Based on the book by Vladik Khononov "Learning Domain-Driven Design: Aligning Software Architecture and Business Strategy".

Learning Domain-Driven Design: Aligning Software Architecture and Business Strategy

Implementing Simple Business Logic

Transaction Script

Active Record

Tackling Complex Business Logic

Domain Model

Value object

  • A value object is an object that can be identified by the composition of its values
  • Value objects are implemented as immutable objects
  • Since the equality of value objects is based on their values rather than on an id field or reference, it’s important to override and properly implement the equality checks
public class Color
{
    public readonly byte Red;
    public readonly byte Green;
    public readonly byte Blue;
    
    public Color(byte r, byte g, byte b)
    {
        this.Red = r;
        this.Green = g;
        this.Blue = b;
    }
    
    public Color MixWith(Color other)
    {
        return new Color(
            r: (byte) Math.Min(this.Red + other.Red, 255),
            g: (byte) Math.Min(this.Green + other.Green, 255),
            b: (byte) Math.Min(this.Blue + other.Blue, 255)
        );
    }
}

Entities

  • An entity is the opposite of a value object
  • It requires an explicit identification field to distinguish between the different instances of the entity
  • Entities are not immutable and are expected to change
  • Value objects describe an entity's properties
class Person
{
    public readonly PersonId Id;
    public Name Name { get; set; }
    
    public Person(PersonId id, Name name)
    {
        this.Id = id;
        this.Name = name;
    }
}

Aggregates

  • An aggregate is an entity: it requires an explicit identification field and its state is expected to change during an instance's lifecycle
  • The goal of the pattern is to protect the consistency of its data
  • The aggregate is a consistency enforcement boundary
  • Its state can only be mutated by executing corresponding methods of the aggregate's public interface
  • An aggregate's public interface is responsible for validating the input and enforcing all of the relevant business rules and invariants
public class Ticket
{
    private UserId          _customer;
    private List<ProductId> _products;
    private UserId          _assignedAgent;
    private List<Message>   _messages;
}

Event-Sourced Domain Model

ddd's People

Contributors

uprinter avatar

Watchers

 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.