From: Julie on
Hello everyone,
You will have to forgive my newbish questions...

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.

I'd appreciate any help anybody can give me.

Thank you very much in advance,

Julie.

From: Cor Ligthert[MVP] on
There are endless constructions to create with Net.
Would you not ask yourself better, "how can I solve something? instead of
how can I create a crazy construction.
I know, knitting can be very funny also for me, but when it only creates a
knot, then it is more a kind of sculpture.

It needs in the list a reference to its own class.

By the way, the TreeNodeCollection is older then the generic list so I wont
assume that it has this construction.

Jmo

Cor

"Julie" <julie(a)home.com> wrote in message
news:eAScZQWyKHA.5364(a)TK2MSFTNGP05.phx.gbl...
> Hello everyone,
> You will have to forgive my newbish questions...
>
> 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.
>
> I'd appreciate any help anybody can give me.
>
> Thank you very much in advance,
>
> Julie.

From: Julie on
Surely though, there must be some standard design principals behind the use
of sub-classes?

When it boils down, that is my actual question... When to use and when not
to use sub-classes.

Do you know of any information I can look up on this?


"Cor Ligthert[MVP]" <Notmyfirstname(a)planet.nl> wrote in message
news:O70hRoZyKHA.5132(a)TK2MSFTNGP05.phx.gbl...
> There are endless constructions to create with Net.
> Would you not ask yourself better, "how can I solve something? instead of
> how can I create a crazy construction.
> I know, knitting can be very funny also for me, but when it only creates a
> knot, then it is more a kind of sculpture.
>
> It needs in the list a reference to its own class.
>
> By the way, the TreeNodeCollection is older then the generic list so I
> wont assume that it has this construction.
>
> Jmo
>
> Cor
>
> "Julie" <julie(a)home.com> wrote in message
> news:eAScZQWyKHA.5364(a)TK2MSFTNGP05.phx.gbl...
>> Hello everyone,
>> You will have to forgive my newbish questions...
>>
>> 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.
>>
>> I'd appreciate any help anybody can give me.
>>
>> Thank you very much in advance,
>>
>> Julie.
>
From: Tom Shelton on
On 2010-03-23, Julie <julie(a)home.com> wrote:
> Surely though, there must be some standard design principals behind the use
> of sub-classes?
>
> When it boils down, that is my actual question... When to use and when not
> to use sub-classes.
>
> Do you know of any information I can look up on this?
>

I don't know - it's pretty subjective. There are some rules that have sort of
perculated out of the whole pattern thing... Things like:

1) Program to interfaces not implementations
2) Favor composition over inheritance
3) Isolate the parts of an application that vary, from those that don't.
4) Code should be closed to change, but open to extension...

etc, etc. I suggest you study up on design patterns. I'm no expert - but, I
feel that becoming familiar with the concept of design patterns and studying
them a bit sort of opend the door to the "next level" so to speak :)

--
Tom Shelton
From: Armin Zingler on
Am 23.03.2010 02:09, schrieb Julie:
> Surely though, there must be some standard design principals behind the use
> of sub-classes?
>
> When it boils down, that is my actual question... When to use and when not
> to use sub-classes.
>
> Do you know of any information I can look up on this?

The term "sub class" can be misleading. If you search for "nested classes"
(or nested types), you find also the following link which says something
about it's usage:

http://msdn.microsoft.com/en-us/library/ms229027.aspx



--
Armin
 |  Next  |  Last
Pages: 1 2
Prev: string functions
Next: AndAlso, OrElse and brackets