Child collection cannot have items

Child collection cannot have items

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


ajj3085 posted on Wednesday, August 30, 2006

Hi,

I have a business requirement I'm trying to implement, and trying to get ideas on how best to handle this.

I have a ProductBundle class, which is a Product (has its own price, part number, etc) that is simply a collection of other non-bundle products.  The bundle's price can be set explicitly or it can be calculated by summing the prices of the constituent products.

During the edit, the user can set how to determine the price; if its set to Calculated, any prices defined for the bundle are cleared (the prices are kept as a list, since a product has different prices for each price list).  I do this on the PriceType property setter.

The part i'm struggling with is that the Prices collection must now remain empty.  My initial though is to set AllowAdd, AllowEdit and AllowRemove to false, and set those properties to true if the price is set back to fixed. 

The problem is that the UI can simply change these values as well.  Is this how I should go about implementing this requirement?  Is there something I can do in the collection class to enforce these rules better?  Also, where would I define a BusinessRule to make sure Prices.Count remains 0?

Thanks
Andy

JoeFallon1 replied on Wednesday, August 30, 2006

I usually have a BO that handles each use case. This is sort of a master BO - it is derived from BusinessBase but it only has a NewBO factory method. It contains all of the other BOs needed for this use case - I think the pattern is called Use Case Controller. (I am used to calling it a Unit Of Work or UOW - but that is probably not the correct name - but I'm not going to re-name all my BOs!)

Anyway - this master BO instantiates the other BOs as needed and makes them available to the UI as Properties. One of the neat things about this approach is that this master BO can have its own Broken Rules which can be as complex as you want and can involve the state of the contained BOs. This is a great place to enforce the rule that if Price is Calculated then Prices.Count=0 must be True.

The contained BOs can be Root objects or children or ROCs or ECCs or any combination. You do not have to change a Root BO to a child just because it is contained by this master BO.

I also implemented the AllRules functionality which loops over a given BO and determines if it has any other BOs and can list out their broken rules too. This method was posted in the old forum. Rocky has not implemented it.

Hope that helps.

Joe

 

 

 

 

Copyright (c) Marimer LLC