What is the concept and how to implement an anemic domain model?

5

I would like to resolve the following doubts about the Anemic Model:

  • What is the Anemic Domain Model ?
  • What are the implementation differences of this template compared to the Object Oriented Model ? If possible, present a small example of the two models in the java language.
  • asked by anonymous 15.10.2014 / 13:23

    2 answers

    6

    What is the Anemic Domain Model?

    The "Anemic Domain Model" is an design pattern of domain-based software development (domain ), where objects that represent business modeling are "anemic", ie devoid of behavior.

    In this pattern, model objects only load data, and business behaviors are exposed by other classes that receive these anemic objects to process them.

    What are the differences in the implementation of this model compared to the Object Oriented Model?

    The answer to this question may be controversial. Some may say that you can not describe differences because the Anemic Domain Model design pattern is also object oriented.

    The notion of difference is born when you accept the proposition that in object orientation an object exposes data and behaviors . In this case, this is the difference: the design pattern Anemic Domain Model rightly proposes that these things be separated into distinct objects.

    A small example of the two models in the java language:

    Anemic Domain Model:

    class ContaaPagar {
    
        double valorDevido;
        boolean pago;
    }
    
    class BaixaContaaPagar {
    
        void baixar(ContaaPagar contaaPagar) {
            contaaPagar.pago = true;
            contaaPagar.valorDevido = 0d;
        }
    }
    

    Another design pattern (DDD, for example):

    class ContaaPagar {
    
        double valorDevido;
        boolean pago;
    
        void baixar() {
            // baixa esta conta a pagar
            pago = true;
            valorDevido = 0d;
        }
    }
    
        
    15.10.2014 / 18:26
    -1

    On this point, imagine that you have requests that need to go through steps. We would have a Request class, RequestEtape1, RequestEtapa2 (these two inheriting from Request), to perform step 2 I need step 1 to complete. If I adopt the DDD, how would I solve the business rule? Would the Entity2 Request entity access the Repository of RequestAtapa1?

    class Pedido {
       int id;
       int numero;
       Date dataPedido;
    }
    
    class PedidoEtapa1 extends Pedido {
       Date dataEtapa1;
    }
    
    class PedidoEtapa2 extends Pedido {
       Date dataEtapa2;
    
       public Boolean etapa1Concluida() {
          ...
          return ?;
       }
    
    }
    
        
    24.09.2015 / 15:12