Whose Responsibility is it?

Whose Responsibility is it?

Old forum URL: forums.lhotka.net/forums/t/3749.aspx


tna55 posted on Saturday, October 20, 2007

Hi,

I am trying to understand the responsibility-driven design and I have a question.

Lets say we have two BOs, Sale (Date, Reference etc) and SaleItem (Price, Quantity etc). We need to get sale total. Both these objects came into being due to Add/Edit Sale use-case.

I am trying to assign responsibility of getting sale total to some BO. My question really is that Sale and SaleItem are responsible, at the moment, to load data and save validated data (much like ProjectTracker BOs). Now this new responsibility of calculating sale total, where should I put this?

Tahir

tmg4340 replied on Saturday, October 20, 2007

Well - given that the sale total is likely to be a summation of SaleItem data, I'd probably put the responsibility for that value on the BusinessListBase collection that stores the SaleItem objects - and then make that property available from the Sale object.  You could certainly move the sale-total functionality to the Sale object, and eliminate the delegation, but that means you can't get the total of the SaleItems if the collection is linked to a different parent object without duplicating code.

I wouldn't put it on SaleItem, because (a) each SaleItem object for a sale would have the same value, and (b) each SaleItem would need to be able to access every other SaleItem in the aforementioned collection in order to get the value.  Since the collection already has access to all the SaleItem objects...

HTH

Copyright (c) Marimer LLC