From: ersatz53 on
On Mar 21, 10:05 pm, "Julie" <ju...(a)home.com> wrote:

> I have a class that has a sub collection class.
>
> Public Class Item
>     Public Collection As ItemCollection
>
>     Public Class ItemCollection
>         Inherits Generic.List(Of Item)
>     End Class
> End Class
>
> I have two questions:
> 1. When is it appropriate to use a sub class like above? I got the idea from
> System.Windows.Forms.Control. But when i look at
> System.Windows.Forms.TreeNode, it doesn't have its collection class as a sub
> class (System.Windows.Forms.TreeNodeCollection). Is there a web site the
> defines the best practices for class and subclass usage?
>
> 2. If i were to inherit Item into ItemDetail, the ItemCollection wouldn't be
> type specific for ItemDetail. So what would I do in this case? Create
> another sub collection class? I don't think ItemDetailCollection could
> inherit ItemCollection.
>

Balena in his book suggests that subclassing was useful for overcoming
the limitations in the VB6 language. He also claims that with the
power of the Windows Forms classes are so powerful that there is
rarely a need to resort to subclassing. (Balena, Francesco. Programing
Visual Basic .NET. p753. Microsoft Press)

/tr
From: Julie on
well, i don't know about anybody else, but i think it is a nice way to
structure code (however, i might not understand it completely).

For example, if i had a class called Order, and this class has a lot of
properties, but also has order lines (a collection of products associated
with an order), rather than have two classes, Order and OrderLine, i could
subclass the line, which then doesn't require the Order prefix. That is, i
would have Order, and Order.Line (sub class of order).

You wouldn't have a Line without an Order.

Does this make sense or am i on the wrong track?

Thanks.


"ersatz53" <tim.rupp(a)gmail.com> wrote in message
news:05803239-9ce2-4400-95e5-9246fe1ee5bf(a)g10g2000yqh.googlegroups.com...
> On Mar 21, 10:05 pm, "Julie" <ju...(a)home.com> wrote:
>
>> I have a class that has a sub collection class.
>>
>> Public Class Item
>> Public Collection As ItemCollection
>>
>> Public Class ItemCollection
>> Inherits Generic.List(Of Item)
>> End Class
>> End Class
>>
>> I have two questions:
>> 1. When is it appropriate to use a sub class like above? I got the idea
>> from
>> System.Windows.Forms.Control. But when i look at
>> System.Windows.Forms.TreeNode, it doesn't have its collection class as a
>> sub
>> class (System.Windows.Forms.TreeNodeCollection). Is there a web site the
>> defines the best practices for class and subclass usage?
>>
>> 2. If i were to inherit Item into ItemDetail, the ItemCollection wouldn't
>> be
>> type specific for ItemDetail. So what would I do in this case? Create
>> another sub collection class? I don't think ItemDetailCollection could
>> inherit ItemCollection.
>>
>
> Balena in his book suggests that subclassing was useful for overcoming
> the limitations in the VB6 language. He also claims that with the
> power of the Windows Forms classes are so powerful that there is
> rarely a need to resort to subclassing. (Balena, Francesco. Programing
> Visual Basic .NET. p753. Microsoft Press)
>
> /tr

From: Captain Jack on
"Julie" <julie(a)home.com> wrote in message
news:uSWZYXGzKHA.5940(a)TK2MSFTNGP02.phx.gbl...
> well, i don't know about anybody else, but i think it is a nice way to
> structure code (however, i might not understand it completely).
>
> For example, if i had a class called Order, and this class has a lot of
> properties, but also has order lines (a collection of products associated
> with an order), rather than have two classes, Order and OrderLine, i could
> subclass the line, which then doesn't require the Order prefix. That is, i
> would have Order, and Order.Line (sub class of order).
>
> You wouldn't have a Line without an Order.
>
> Does this make sense or am i on the wrong track?
>
> Thanks.

I don't know if there really is a good standard, but what I do is declare
every public class, structure, and enumeration at the same level. If I have
a class that doesn't need to be used anywhere but within one class, I make
it private and define it in there. My main reason is that the autoindenting
doesn't get confusining (it's easier for me to tell which class I'm working
in, especially if it has a lot of code) and declaring variables of a nested
class doesn't get out of hand by being too long to read easily.

The question I always ask myself on this kind of design issue is, "If I get
hit by a bus on my way to work tomorrow, will somebody else be able to
figure out what I was doing, and why?" I think it's most important to be
consistent, and try to have every developer in the shop be doing things the
same way.

--
Jack


First  |  Prev  | 
Pages: 1 2
Prev: string functions
Next: AndAlso, OrElse and brackets