'Visual Basic 2010 Containment Object Oriented Programming Module PointAndLineTestFixtures Sub Main() PointTestFixture() LineTextFixture() ' Console.ReadLine() End Sub Sub PointTestFixture() Dim point1 As Point = New Point Console.WriteLine(point1.X = 0) Console.WriteLine(point1.Y = 0) ' point1.X = 1 Console.WriteLine(point1.X = 1) Console.WriteLine(point1.Y = 0) ' point1.Y = 3 Console.WriteLine(point1.X = 1) Console.WriteLine(point1.Y = 3) End Sub Sub LineTextFixture() Dim line1 As Line = New Line Console.WriteLine(line1.StartPoint Is Nothing) Console.WriteLine(line1.EndPoint Is Nothing) Console.WriteLine(line1.Length = 0) ' Dim startPoint As Point = New Point With {.X = 1, .Y = 4} line1.StartPoint = startPoint Console.WriteLine(line1.StartPoint Is startPoint) Console.WriteLine(line1.EndPoint Is Nothing) Console.WriteLine(line1.Length = 0) ' Dim endPoint As Point = New Point With {.X = 5, .Y = 1} line1.EndPoint = endPoint Console.WriteLine(line1.StartPoint Is startPoint) Console.WriteLine(line1.EndPoint Is endPoint) Console.WriteLine(line1.Length = 5) End Sub End Module Class Point Private m_X As Integer Public Property X() As Integer Get X = m_X End Get Set(ByVal value As Integer) m_X = value End Set End Property Private m_Y As Integer Public Property Y() As Integer Get Y = m_Y End Get Set(ByVal value As Integer) m_Y = value End Set End Property End Class Class Line Private m_StartPoint As Point Public Property StartPoint() As Point Get StartPoint = m_StartPoint End Get Set(ByVal value As Point) m_StartPoint = value End Set End Property Private m_EndPoint As Point Public Property EndPoint() As Point Get EndPoint = m_EndPoint End Get Set(ByVal value As Point) m_EndPoint = value End Set End Property Public ReadOnly Property Length() As Double Get If StartPoint IsNot Nothing AndAlso EndPoint IsNot Nothing Then Dim side1 As Integer = Math.Abs(StartPoint.X - EndPoint.X) Dim side2 As Integer = Math.Abs(StartPoint.Y - EndPoint.Y) Length = Math.Sqrt(Math.Pow(side1, 2) + Math.Pow(side2, 2)) End If End Get End Property End Class 'Bezoek www.vbvoorbeelden.be voor meer Visual Basic voorbeelden. 'Copyright - De Wolf / vbvoorbeelden - 2003-2011 - Alle rechten voorbehouden.