Collections in VB.Net

Discussion in 'Scripting & Programming' started by Fergal1982, Apr 3, 2008.

  1. Fergal1982

    Fergal1982 Petabyte Poster

    4,196
    172
    211
    I'm getting a little confused by how to implement collections within vb.net.

    Basically I have two classes: Parent; and Child.

    The Parent class can have one or more Child objects associated with it. I want to add a method to the Parent class that returns a collection of the Children associated with it.

    But, as I understand it, I need to implement a collections class for the Child object. Problem is, the details I've found online just seem really confusing to me. I've tried creating a class and implementing the Icollection, but i just dont understand how I need to put it together.

    Does anyone have any good links for learning this?
     
    Certifications: ITIL Foundation; MCTS: Visual Studio Team Foundation Server 2010, Administration
    WIP: None at present
  2. dmarsh
    Honorary Member 500 Likes Award

    dmarsh Petabyte Poster

    4,305
    503
    259
    Try reading these :-

    http://www.atomicobject.com/pages/Aggregation
    http://en.wikipedia.org/wiki/Object_composition#Aggregation

    http://msdn2.microsoft.com/en-us/library/395dc977.aspx

    Theres no need to implement a collection interface unless you want to create your own collection class, or data structure, for simple aggregation this is not required, just use the languages array or collection contructs or classes.

    If you mean parent and child in the literal real world sense then you probably want to model things using other OO constructs, for example a Parent and a Child are both Persons indicating inheritence. You then probably want containment by reference as some peoples parents may be other peoples children. Of course you should create inheritance heirachies based on functionality, so if there is none, in reality you would probably just model it with a single Person class.

    http://en.wikipedia.org/wiki/Inheritance_(computer_science)

    Martin Fowlers Analysis Patterns is an excellent introduction into such things. However patterns information is everywhere these days so buying the book is not necessary if you are prepared to dig a bit.

    http://martinfowler.com/apsupp/accountability.pdf
     
  3. Fergal1982

    Fergal1982 Petabyte Poster

    4,196
    172
    211
    Cheers mate, they arent actually parent/child in the literal sense, just in the sense that the parent object has multiple children objects.
     
    Certifications: ITIL Foundation; MCTS: Visual Studio Team Foundation Server 2010, Administration
    WIP: None at present

Share This Page

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.