PC Review


Reply
Thread Tools Rate Thread

Class Design with Collection Classes

 
 
Julie
Guest
Posts: n/a
 
      22nd Mar 2010
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.

 
Reply With Quote
 
 
 
 
Cor Ligthert[MVP]
Guest
Posts: n/a
 
      22nd Mar 2010
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.


 
Reply With Quote
 
Julie
Guest
Posts: n/a
 
      23rd Mar 2010
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]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> 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.

>

 
Reply With Quote
 
Tom Shelton
Guest
Posts: n/a
 
      23rd Mar 2010
On 2010-03-23, Julie <(E-Mail Removed)> 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
 
Reply With Quote
 
Armin Zingler
Guest
Posts: n/a
 
      23rd Mar 2010
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
 
Reply With Quote
 
ersatz53
Guest
Posts: n/a
 
      23rd Mar 2010
On Mar 21, 10:05*pm, "Julie" <ju...@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'tbe
> 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
 
Reply With Quote
 
Julie
Guest
Posts: n/a
 
      25th Mar 2010
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" <(E-Mail Removed)> wrote in message
news:05803239-9ce2-4400-95e5-(E-Mail Removed)...
> On Mar 21, 10:05 pm, "Julie" <ju...@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


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create a collection of custom classes in another custom class kagard Microsoft Access 3 12th Jun 2011 07:57 PM
static classes, nested class, public class puzzlecracker Microsoft C# .NET 3 3rd Nov 2008 03:22 PM
Can't get collection to save when using collection of custom class as property of control in VS 2005 J.Edwards Microsoft Dot NET Compact Framework 0 10th Jan 2006 04:44 AM
Collection Class Design Question (Compound Key) =?Utf-8?B?SnVzdGluUw==?= Microsoft Dot NET Framework 1 24th Mar 2005 08:08 PM
How to design the class architectures if the classes have some save functions? Quentin Huo Microsoft C# .NET 1 25th Feb 2005 11:25 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:16 AM.