Pioneer Plot: Consumption of the domain model

The last Pioneer Plot posed this question:

Congratulations! You are developing a domain model layer. Assuming your UI will send you dumb data transfer objects, how will your application layer consume it such that the business logic in your entities, value objects, aggregates, and so forth is not completely by-passed by blind mapping from DTOs to domain objects?

My answer

This all comes down to how you interpret what is coming into your application layer. Develop your domain model as normal. Pack as much relevant business logic as you can in the right nooks and crannies. Then when it comes time for the application layer to consume the domain model, interpret the data coming in and take actions on the domain model as necessary.

Definitely need an example here.

class ApplicationLayer
{
  void updateEquipment(int oldID, String oldStatus, String newStatus)
  {
    if(!oldStatus.equals(newStatus)) // need to update status
    {
      Equipment equip = equipFactory.createFrom(oldID, oldStatus);
      if(newStatus.equals("SPRE"))
      {
        equip.spare();
        equip.room().incrementSpareCount();
      }
      if(newStatus.equals("INUS"))
      {
        equip.inUse();
      }
      equipRepo.save(equip);
    }
  }
}

Next plot

You have a domain layer, but your repositories and factories need to go to and from a legacy system in order to accomplish persistence and re-use existing code. You’d like to cordon those references off into an Anti-Corruption Layer.

But oh no! One of your polymorphic entities double-dispatches to one of those factories, and that puts a reference to the legacy stuff in your domain model. What do you do?

Catch the virus. M1D1 out.

COME my tan-faced children,
Follow well in order, get your weapons ready,
Have you your pistols? have you your sharp-edged axes?
Pioneers! O pioneers!

For we cannot tarry here,
We must march my darlings, we must bear the brunt of danger,
We the youthful sinewy races, all the rest on us depend,
Pioneers! O pioneers!

Announcer: You’re reading the EIP web-ring.

Leave a Reply