Children of one collection or many help

Children of one collection or many help

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


Wal972 posted on Tuesday, May 23, 2006

Hi.

How do I set up a object for example an invoice which has a collection of line items which are different types.

ie. Serivce, products, payments etc. each with their own requirements and functions.

Do I have my root object contain one collection or multiple for the different types are all of LineItem Type.

Help

pfeds replied on Tuesday, May 23, 2006

It seems to me like you want one collection of line items.  A line item would contain basic information that you can display in your invoice.

If you opt for your former method of having a number of child collections for service, product, etc then that could get messy when you need to add yet another type of line item.

By the way, you would want three classes.  Your Invoice would be an editable root, and you also want a read only LineItemList that contains read only LineItemInfo items.

You may also need to implement a way of navigating from a LineItemInfo object to what it actually represents, such as a full fat Service or Product.

DavidDilworth replied on Tuesday, May 23, 2006

Is the relationship you're describing between Invoice and LineItem "An Invoice has a bunch of associated LineItems (of any type)".

If yes, then the answer is indeed a single child Collection of type LineItemList (say).  In this scenario it is likely that LineItem itself is merely an abstract base class (ABC) from which your concrete line item classes inherit.

If no, then what you might be saying is that you need to know that an Invoice can have associated Payments.  If this is the case then you need different child collections for each of the types you are ultimately really interested in.

It depends what requirement you are trying to meet with your Invoice object and your LineItem object.

ajj3085 replied on Tuesday, May 23, 2006

This also may be a good case for inhertance.  You have an Invoice, a LineItems collection, an abstract LineItem class.  You would than have ServiceLineItem, ProductLineItem, PaymentLineItem, etc.  each with their own rules.

Andy

Wal972 replied on Tuesday, May 23, 2006

Thats exactly what i mean. My problem is creating it. It I have a collection Line items, do I have its transactions as the abstract LineItem Class. and will it accept that. If not what ?

Also when I create the collection how do I tell it to create the different items Service etc. Do I use a select case and determine it at the time of creation for display purposes.

Thanks for the help

RockfordLhotka replied on Tuesday, May 23, 2006

You are right - this is a problem due to the lack of polymorphic behavior in generics. Well, that and an oversight on my part...

So in version 2.0.1 you'll see an answer to this problem, where I've changed BusinessListBase and Core.BusinessBase to allow for polymorphic child types in a collection. The prototype code for this is in cvs right now, and involves a new interface (IEditableBusinessObject) and also a change to IEditableCollection.

The end result is that you can define a common (non-generic) interface that all your line item classes implement - then you declare your collection like this:

Public Class MyLineItems
  Inherits Csla.BusinessListBase(Of MyLineItems, ILineItem)

I'll have a beta 2 of 2.0.1 on my web site later this week so you can try this out. Also I'll be checking in some unit tests for this concept in the near future so you can see how it is used.

Wal972 replied on Sunday, June 11, 2006

OK, I have created my collection with the interface.  How do I reference the a fetch call for the collection.

Secondly how do I reference a particular line item type within the collection ?

Thanks

Copyright (c) Marimer LLC