If you are forced to use an Anemic domain model, where do you put your business logic and calculated
        Posted  
        
            by Jess
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Jess
        
        
        
        Published on 2009-12-19T16:33:06Z
        Indexed on 
            2010/04/08
            2:13 UTC
        
        
        Read the original article
        Hit count: 386
        
Our current O/RM tool does not really allow for rich domain models, so we are forced to utilize anemic (DTO) entities everywhere. This has worked fine, but I continue to struggle with where to put basic object-based business logic and calculated fields.
Current layers:
- Presentation
 - Service
 - Repository
 - Data/Entity
 
Our repository layer has most of the basic fetch/validate/save logic, although the service layer does a lot of the more complex validation & saving (since save operations also do logging, checking of permissions, etc). The problem is where to put code like this:
Decimal CalculateTotal(LineItemEntity li)
{
  return li.Quantity * li.Price;
}
or
Decimal CalculateOrderTotal(OrderEntity order)
{
  Decimal orderTotal = 0;
  foreach (LineItemEntity li in order.LineItems)
  {
    orderTotal += CalculateTotal(li);
  }
  return orderTotal;
}
Any thoughts?
© Stack Overflow or respective owner