What is the concept and how to implement an Anemic Domain Model?

Asked

Viewed 2,765 times

9

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

  1. What is the The Anemic Domain Model?
  2. What are the differences of implementation of that model compared to Object-Oriented Model? If possible, present a small example of the two models in the java language.
  • If I’m not mistaken, the other day you made an equal/similar question, where you ended up closing... Although this is a pertinent question, do you already have any idea about the Anemic Model? Or is it homework?

  • @Cesarean Michael I open this post to be a way of research for other people and have a notion with object orientation, but not with this model. And just because my questions about this subject are pertinent is not a "homework", they are my own doubts.

  • Who voted to close the question is not clear: I think you are the one who did not understand the question.

  • 3

    The full term is The Anemic Domain Model or Anemic Model of Domain. It’s a controversial subject. I personally think it’s an anti-pattern. If no one else answers, later from home I make a reply.

  • @Renan blz.. if you post your answer helps very vlw

2 answers

7


What is the Anemic Domain Model?

The English "Anemic Domain Model" Anemic Domain Model, is a Pattern design business domain-based software development (Domain), where objects representing business modeling (model) are "anemic", that is: devoid of behavior.

In this Pattern, the model objects only load the data, and the 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 differences cannot be described because the Anemic Domain Model Pattern design is also object-oriented.

The notion of difference is born when you accept the proposition that, in object orientation, an object exposes data and behaviour. In this case, this is the difference: the Pattern design Anemic Domain Model proposes precisely that these things be separated into different 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;
    }
}

Other design Pattern (DDD, for example):

class ContaaPagar {

    double valorDevido;
    boolean pago;

    void baixar() {
        // baixa esta conta a pagar
        pago = true;
        valorDevido = 0d;
    }
}
  • if a class had only the attributes, get and setters and considered anemic?

  • @Pedrorangel No. How you will call it depends on its function and many issues according to your system’s design decisions.

-1

At this point, imagine that you have requests that need to go through stages. We would have a Request, Pedidoetapa1, Pedidoetapa2 class (these two inheriting from Request), to perform step 2 I need step 1 to be completed. If I adopted the DDD, how would I solve the business rule? Entity from Pedidoetapa2 would access the Pedidoetapa1 repository?

class Pedido {
   int id;
   int numero;
   Date dataPedido;
}

class PedidoEtapa1 extends Pedido {
   Date dataEtapa1;
}

class PedidoEtapa2 extends Pedido {
   Date dataEtapa2;

   public Boolean etapa1Concluida() {
      ...
      return ?;
   }

}
  • this seems to me more a question than an answer, next time, use comments or ask your own question! :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.