Git Product home page Git Product logo

saasovation's Introduction

SaasOvation demo DDD implementation

This code is being written during @VaughnVernon 's #IDDDtour in Belgium. It is a very opinionated approach that I will use later on for my presentation. I am quite sure that there are or will be some caveats in this implementation, but the idea is to get you thinking about delaying your infrastructure decisions.

It should not matter where or how you store your state, if you do respect this approach

It might look a bit like this:

That looks painful

... but I found out that the flow is actually pretty nice when you start developing like this ...

Some context

Due to my more recent experiments with Erlang, I think I might have found a way to model the domain in a way that refactoring does not hurt as much as the more conventional approach, and that it allows you to remove infrastructure completely out of the model.

It looks rather similar to the actor model, and is based on the fact that Erlang actually uses processes that communicate with eachother while respecting OO principles the way they were intended.

In Erlang, while counterintuitive from the perspective of a conventional OO thinker, all OO principles are respected by having processes that communicate through messaging only:

  • Dynamic dispatch
  • Encapsulation
  • Polymorphism
  • Inheritance
  • Open recursion

If you see erlang code combined with DDD, there is almost NO infrastructure code there...

Other implementations

I think it is interesting to see how others implemented this:

Feel free to send a pull request to add your own! Just click the README.md file in the browser and press edit!!! #EasyPeasy

As Alan Kay points out, the original focus in OO was not about the state, but about the interactions/messaging between objects.

This implementation is trying to achieve this by applying CQRS on a really low level. Some might suggest me to use F# or similar instead, and they might be right.

Motivation

By doing this, you really postpone the infrastructure decisions to the very end of the solution. You make everything explicit, and really add an extra (but understandable) layer of explicitness. One important thing to notice here, is that the Query side really needs to respect the TDA principle, in order for the domain to be completely detached from the implementation.

This approach is an evolution of the technique used by @abdullin.

Code

This is an example, it might not be up to date, so check here for the latest version.

    public class Product: IHandleDomainCommands
    {
        private IModifyProductState Changes;
        private IQueryProductState Queries;

        public Product(ProductState State) : this(State, State) { }

        public Product(IModifyProductState Changes,IQueryProductState Queries) {
            this.Changes = Changes;
            this.Queries = Queries;
        }

        public void ActivateProduct(TenantId Tenant, ProductId Id, string Name, string Description)
        {
            MustBeActive(Tenant);
            Guard.Against(Queries.IsActive(Tenant,Id),"This product is already active.");
            Changes.ProductActivated(Tenant, Id, Name, Description);
        }

        public void RequestFeature(TenantId Tenant, ProductId Product, IssueId Id, string Name, string Description,IssueAssignerId Assigner)
        {
            MustBeActive(Tenant,Product);
            MustBeActive(Tenant,assigner:Assigner);
            Changes.IssueRegistered(Tenant,Product,Id, Name, Description,IssueType.Feature,Assigner);
        }

        public void ReportDefect(TenantId Tenant, ProductId Product, IssueId Id, string Name, string Description,IssueAssignerId Assigner)
        {
            MustBeActive(Tenant, Product);
            Changes.IssueRegistered(Tenant, Product, Id, Name, Description,IssueType.Defect,Assigner);
        }

        public void CloseIssue(TenantId Tenant, ProductId Product, IssueId Id)
        {
            MustBeActive(Tenant, Product, Id);
            Changes.IssueClosed(Tenant, Product, Id);
        }

        void MustBeActive(TenantId tenant = null, ProductId product = null, IssueId ticket = null,IssueAssignerId assigner=null)
        {
            if (tenant != null) Guard.That(Queries.IsActive(tenant), "This is an inactive tenant");
            if (product != null) Guard.That(Queries.IsActive(tenant,product), "This is an inactive product");
            if (ticket != null) Guard.That(Queries.IsActive(tenant, product, ticket), "This is an inactive ticket");
            if (assigner != null) Guard.That(Queries.IsActive(tenant, assigner), "This is an inactive assigner");
        }
    }

saasovation's People

Contributors

tojans avatar

Stargazers

Kanata Miyahana avatar Marcos Ricardo avatar Victor Hugo Viana avatar Léonard Binet avatar  avatar Mehdi Hadeli avatar Nandy avatar Marek Kaluzny avatar liujh avatar tangyao avatar  avatar DavisZan avatar David Jiménez avatar Rafael T. C. Soares (A.K.A Tuelho) avatar Giri S. avatar  avatar Rico Moorman avatar  avatar Povilas Skruibis avatar Bram De Moor avatar Miguel Angel Diez Bielsa avatar Leonardo Bessa avatar Yves M. avatar Nick Portelli avatar Meligy avatar Geert Huls avatar Cory Taylor avatar Yin Zhang avatar  avatar

Watchers

Morten Jokumsen avatar  avatar Tomasz Jaskula avatar James Cloos 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.