Object Orientation

Moderators: None (Apply to moderate this forum)
Number of threads: 44
Number of posts: 76

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Help with Object that contains 2 other objects vb.net Posted by pdidow on 22 Jan 2010 at 2:51 PM
I have 3 classes. They are called Boot,Head,and Shell. A boot contains both a Set of Head objects and a set of Shell objects.
My classes:

Head.vb
-------------
Option Explicit On
Public Class Head
    Inherits BusinessEntity.HeadSet
#Region "Private Variables"
    Private _iVesselID As Integer
    Private _iHeadID As Integer
#End Region

#Region "Constructors"
    Public Sub New()

    End Sub
    Public Sub New(ByVal iVesselID As Integer, ByVal iHeadID As Integer)
        _iVesselID = iVesselID
        _iHeadID = iHeadID
    End Sub
#End Region

#Region "Public Properties"
    Public Property iVesselID() As Integer
        Get
            Return _iVesselID
        End Get
        Set(ByVal iValue As Integer)
            _iVesselID = iValue
        End Set
    End Property
    Public Property iHeadID() As Integer
        Get
            Return _iHeadID
        End Get
        Set(ByVal iValue As Integer)
            _iHeadID = iValue
        End Set
    End Property
#End Region

End Class
Public Class HeadSet
    Inherits Collections.ArrayList

    Public Shadows Function Add(ByVal oValue As Head) As Integer
        If Not oValue Is Nothing Then
            MyBase.Add(oValue)
        End If
    End Function

    Default Public Shadows Property Item(ByVal iIndex As Integer) As Head
        Get
            Return CType(MyBase.Item(iIndex), Head)

        End Get
        Set(ByVal Value As Head)
            MyBase.Item(iIndex) = Value
        End Set
    End Property

End Class

Shell.vb
------------
Option Explicit On
Public Class Shell
    Inherits BusinessEntity.ShellSet

#Region "Private Variables"
    Private _iVesselID As Integer
    Private _iShellID As Integer
#End Region

#Region "Constructors"
    Public Sub New()

    End Sub
    Public Sub New(ByVal iVesselID As Integer, ByVal iShellID As Integer)
        _iVesselID = iVesselID
        _iShellID = iShellID
    End Sub
#End Region

#Region "Public Properties"
    Public Property iVesselID() As Integer
        Get
            Return _iVesselID
        End Get
        Set(ByVal iValue As Integer)
            _iVesselID = iValue
        End Set
    End Property
    Public Property iShellID() As Integer
        Get
            Return _iShellID
        End Get
        Set(ByVal iValue As Integer)
            _iShellID = iValue
        End Set
    End Property
#End Region
End Class

Public Class ShellSet
    Inherits Collections.ArrayList

    Public Shadows Function Add(ByVal oValue As Shell) As Integer
        If Not oValue Is Nothing Then
            MyBase.Add(oValue)
        End If
    End Function

    Default Public Shadows Property Item(ByVal iIndex As Integer) As Shell
        Get
            Return CType(MyBase.Item(iIndex), Shell)

        End Get
        Set(ByVal Value As Shell)
            MyBase.Item(iIndex) = Value
        End Set
    End Property

End Class


And Boot.vb
-------------
Option Explicit On
Public Class Boot
    'Contains a head and shell
#Region "Private Variables"
    Private _oHeadSet As New HeadSet
    Private _oShellSet As New ShellSet
    Private _iBootID As Integer
    Private _iVesselID As Integer
#End Region

#Region "Constructors"
    Public Sub New()
        _oHeadSet = New BusinessEntity.HeadSet
        Dim oHead As New Head
        _oHeadSet.Add(oHead)
        _oShellSet = New BusinessEntity.ShellSet
        Dim oShell As New Shell
        _oShellSet.Add(oShell)

    End Sub
    Public Sub New(ByVal oHeadSet As HeadSet, ByVal oShellSet As ShellSet, ByVal iBootID As Integer, ByVal iVesselID As Integer)
        _oHeadSet = New BusinessEntity.HeadSet
        _oShellSet = New BusinessEntity.ShellSet
        Dim oHead As New Head
        Dim oShell As New Shell
        _oHeadSet.Add(oHead)
        _oShellSet.Add(oShell)
        _iBootID = iBootID
        _iVesselID = iVesselID

    End Sub
#End Region

#Region "Public Properties"
    Public Property oHeadSet() As BusinessEntity.HeadSet
        Get
            Return _oHeadSet
        End Get
        Set(ByVal oValue As HeadSet)
            _oHeadSet = oValue
        End Set
    End Property

    Public Property oShellSet() As BusinessEntity.ShellSet
        Get
            Return _oShellSet
        End Get
        Set(ByVal oValue As ShellSet)
            _oShellSet = oValue
        End Set
    End Property

    Public Property iBootID() As Integer
        Get
            Return _iBootID
        End Get
        Set(ByVal iValue As Integer)
            _iBootID = iValue
        End Set
    End Property
  
    Public Property iVesselID() As Integer
        Get
            Return _iVesselID
        End Get
        Set(ByVal iValue As Integer)
            _iVesselID = iValue
        End Set
    End Property
#End Region
End Class


Public Class BootSet
    Inherits Collections.ArrayList

    Public Shadows Function Add(ByVal oValue As Boot) As Integer
        If Not oValue Is Nothing Then
            MyBase.Add(oValue)

        End If
    End Function

    Default Public Shadows Property Item(ByVal iIndex As Integer) As Boot
        Get
            Return CType(MyBase.Item(iIndex), Boot)

        End Get
        Set(ByVal Value As Boot)
            MyBase.Item(iIndex) = Value
        End Set
    End Property

End Class


And a function from my code behind webpage, to implement
 Public Function BuildEM() As BusinessEntity.BootSet
        oHead = New BusinessEntity.Head
        oHeadSet = New BusinessEntity.HeadSet
        oShell = New BusinessEntity.Shell
        oShellSet = New BusinessEntity.ShellSet
        oBootSet = New BusinessEntity.BootSet

        oHead.iHeadID = 1
        oHeadSet.Add(oHead)
        oShell.iShellID = 1
        oShellSet.Add(oShell)
        oBoot = New BusinessEntity.Boot
     
        oBoot.iBootID = 1

        oBoot.iVesselID = 30

        oBootSet.Add(oBoot)
        Return oBootSet
    End Function

What is in the returned oBootSet is not what I expect.
I have a bootset returned, containing a headset and a shellset. There are no items in this set, as my watch indicates:
- oBootSet Count = 1 BusinessEntity.BootSet
- (0) {BusinessEntity.Boot} Object
- BusinessEntity.Boot {BusinessEntity.Boot} BusinessEntity.Boot
_iBootID 1 Integer
_iVesselID 30 Integer
- _oHeadSet Count = 1 BusinessEntity.HeadSet
(0) Count = 0 Object
- _oShellSet Count = 1 BusinessEntity.ShellSet
(0) Count = 0 Object
iBootID 1 Integer
iVesselID 30 Integer
- oHeadSet Count = 1 BusinessEntity.HeadSet
(0) Count = 0 Object
- oShellSet Count = 1 BusinessEntity.ShellSet
(0) Count = 0 Object


What am i doing wrong?Please Help!!




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.