Concerns Separated?

If business rules, logging and persistence are being done in the same method, it is not good design.

Business rule processing, logging and persistence are unrelated activities and should not happen in the same method body. If you want to find out how to do this, feel free to contract my services but to give a clue it’s about a combination of what goes on before and after the method call as well as what’s implemented behind the business object interfaces that are passed into that call.

For example…

public void updatePriceWithTax(BusinessContext pContext, State pState, BusinessObject pObject)
{
   TaxRate rate = pContext.getTaxRate(pState);

   s_Logger.debug("Tax rate is " + rate.getRate());

   pObject.adjustPrice(rate);

   m_BusinessDao.save(pObject);
}

…the following lines…

   s_Logger.log(Logger.DEBUG, "Tax rate is " + rate.getRate());
   ...
   m_BusinessDao.save(pObject);

…should not be there as what has logging and persistence got to do with the business operations? I’m willing to place a fairly decent sized bet that this kind of thing can be found in just about 100% of business logic out there.

Leave a Comment