Most Simple Aggregation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dave Johnson

    #1

    Most Simple Aggregation

    greetings,



    can any one show sample example of aggregation in any .net code vb.net
    or C#



    i guess it shouldnt be that hard but i searched a lot without finding
    anything that explains the issue in code. thanks for your reply


    Sharing makes All the Difference

    --
    Sent via .NET Newsgroups

  • Jeff Louie

    #2
    Re: Most Simple Aggregation

    Containment represents a HAS_A relationship between the whole and a
    part.
    So a car IS_A motorized vehicle, but HAS_A radio. The two relationships
    can
    be expressed in code thusly:

    class Radio
    {
    ...
    }
    class Vehicle
    {
    ...
    }
    class Car : Vehicle
    {
    Radio r= new Radio();
    }
    An instance of Car contains an instance of a Radio so that the lifetimes
    of the
    radio and car are intertwined. This is "containmen t by ownership" making
    Car
    an example of a composite class.

    Containment can also be accomplished using references to external
    objects.
    "Containmen t by reference" can be expressed in code thusly:

    class Radio
    {
    ...
    }
    class Vehicle
    {
    ...
    }
    class Car : Vehicle
    {
    private Radio r;
    public Car(Radio r) {
    ...
    this.r= r;
    }
    }
    You can then create an instance of Car like this:

    class Class1
    {
    [STAThread]
    static void Main(string[] args)
    {
    Radio r= new Radio();
    Car c= new Car(r);
    }
    }

    Regards,
    Jeff

    *** Sent via Developersdex http://www.developersdex.com ***

    Comment

    Working...