No PropertyHasChanged on ReadOnlyBase?

No PropertyHasChanged on ReadOnlyBase?

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


hurcane posted on Friday, September 08, 2006

I am in need of advice again for a complex scenario. This is kind of a follwup from a previous thread. First, let me give a little background into my usage scenario.

I have an OrderDetail object that has to estimate its cost. The OrderDetail object collaborates with an InventoryItemInfo object that has some detailed logic that is dependent on the quantity from the OrderDetail record. InventoryItemInfo is a ROB-derived object. It is also used to show status information the user needs to complete their order entry task.

InventoryItemInfo only worked with items that were defined in the database. Now we have a scenario where the same OrderDetail has to deal with an InventoryItemInfo that is not in the database yet. The estimated cost logic is different, which leads to my current problem.

I did some refactoring, and now I have replaced references to InventoryItemInfo with an IInventoryItemInfo interface. An InventoryItemInfoFactory was created to return an IInventoryItemInfo type. My existing class was changed to ExistingInventoryItemInfo and I have a new class, NewInventoryItemInfo. Both classes implement IInventoryItemInfo. The logic within NewInventoryItemInfo is collaborating with an editable root object, NewInventoryEdit. The user can change a value on the NewInventoryEdit object that is a factor in the estimated cost logic. The users want the status display and the OrderDetail to automatically refresh.

So, I made the NewInventoryItemInfo handle the events from the NewItemEdit object. I had planned to raise a PropertyChanged event from NewInventoryItemInfo that would cause data binding to refresh the display. However, this was quickly foiled because ReadOnlyBase does not have a PropertyHasChanged event.

Should I change my NewInventoryItemInfo object to be a BusinessBase object? I think that will solve my issue, but it seems unnatural to have a BusinessBase object that has no writable properties and can't be saved.

I have read on the forums other users who have implemented an internal refresh on their status objects. Are these objects derived from ReadOnlyBase or BusinessBase?

Has anybody dealt with this kind of issue in a different way?
 

RockfordLhotka replied on Friday, September 08, 2006

The simplest thing might be to inherit from BusinessBase, so you can call OnPropertyChanged (not PropertyHasChanged, because you don't want to use the validation and dirty features).

But I agree, that seems like a mis-use. So a better answer is probably to copy the PropertyChanged event code from Core.BindableBase to your business class. Or create you own base class that subclasses ROB to includes this code, and then inherit from your new base class.

hurcane replied on Friday, September 08, 2006

Rocky,

Thanks for the quick response. I think I will go with a subclass (DynamicReadOnlyBase) and copy the code. You saved me at least 30 minutes of time by pointing me directly to Core.BindableBase!

Copyright (c) Marimer LLC