Prev | Current Page 89 | Next

Guy Fouch?©, Trey Nash

"Accelerated VB 2008"

Consider the following code, which represents a container class that
contains instances of GeometricShape:
Imports System.Collections
Public MustInherit Class GeometricShape
Public MustOverride Sub Draw()
End Class
Public Class Rectangle
Inherits GeometricShape
Public Overrides Sub Draw()
System.Console.WriteLine("Rectangle.Draw")
End Sub
End Class
Public Class Circle
Inherits GeometricShape
CHAPTER 3 n CLASSES AND STRUCTURES 43
Public Overrides Sub Draw()
System.Console.WriteLine("Circle.Draw")
End Sub
End Class
Public Class Drawing
Implements IEnumerable
Private Shapes As ArrayList
Public Sub New()
Shapes = New ArrayList()
End Sub
Public Function GetEnumerator() As IEnumerator _
Implements Collections.IEnumerable.GetEnumerator
Return New Iterator(Me)
End Function
Public Sub Add(ByVal Shape As GeometricShape)
Shapes.Add(Shape)
End Sub
Private Class Iterator
Implements IEnumerator
Private Position As Integer
Private Drawing As Drawing
Public Sub New(ByVal Drawing As Drawing)
Me.Drawing = Drawing
Me.Position = -1
End Sub
Public Sub Iterator(ByVal Drawing As Drawing)
Me.Drawing = Drawing
Me.Position = -1
End Sub
Public Sub Reset() Implements Collections.IEnumerator.Reset
Position = -1
End Sub
Public Function MoveNext() As Boolean _
Implements Collections.


Pages:
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
życzenia gustowne meble katowice gustowne meble katowice bajka dieta light