Readonly editable child

Readonly editable child

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


jasonlaw posted on Sunday, August 16, 2009

Let say I have a DeliveryOrder object and it refers to an Order object, for now to make it simple 1 DO can cater for 1 Order only. Since I want reuse the Order object which subclass from BusinessBase and contains child collection of OrderItems, I have a reference attribtue in DO to Order.
Question: Should I mark the Order as child when I populated it? How can I make it as readonly since DO cannot alter Order? Can I turn off the Undoable and Serializable to Order only to improve the performance?

Thanks in advance.

tmg4340 replied on Monday, August 17, 2009

I think you're going to be better off not re-using your Order object.

CSLA objects are designed around use cases, and it sounds like you have different use cases for your "order".  Trying to re-use an editable object in a read-only scenario - not to mention the parent-and-child switch - is very likely to cause you many headaches for little value.

Re-use is not an overarching goal, and is really only useful where the situations are exactly the same.  It's not uncommon at all for there to be multiple versions of the same data in different objects, because the objects do different things.  That's not to say that you can't refactor the common functionality into a common module, but ultimately in your situation I'd create two different objects - one an editable object (which subclasses BusinessBase), the other a read-only object (which subclasses ReadOnlyBase).  You'll get the child functionality on your read-only object if you use the child methods of the DataPortal when interacting with your read-only object; otherwise you'll need to call "MarkAsChild" manually.

(To answer your final question, you can't really "turn off" the undoable/serializable functionality on a CSLA object.  Nor do you really need to, as they shouldn't cause you any performance issues if you don't use them.)

HTH

- Scott

Copyright (c) Marimer LLC