onedaywhen,
I'm not sure of an article, however here is the sample loosely (read
quickly) translated into VB.NET. Notice the Friend vs. Public on the Sub
New. Sub New is called the constructor, its used in the creation of a new
object. Notice on the Spoke constructor, the PartNumber & Allow are passed
as parameters to the constuctor.
All the classes are public, which means they can be used outside of the
assembly. Some of the constructors are Friend, which means that only the
containing assembly can create one of those objects. Some of the
constructors are public, which means that referencing assemblies can create
those objects.
A public method can be used by assemblies outside of this assembly, a Friend
method can only be used by other classes within this assembly.
The problem with this object model, is you cannot buy a new frame for your
bicycle or new wheels, or new spokes. The Readonly on the fields ensure that
the instance variable will not be modified after the object has been
constructed, the constructor can set the field, then its 'frozen'.
Public Class Bicycle
Private ReadOnly m_frame As Frame
Public Sub New()
m_frame = New Frame
End Sub
Public ReadOnly Property Frame() As Frame
Get
Return m_frame
End Get
End Property
End Class
Public Class Frame
Private ReadOnly m_frontWheel As Wheel
Private ReadOnly m_rearWheel As Wheel
Friend Sub New()
m_frontWheel = New Wheel
m_rearWheel = New Wheel
End Sub
Public ReadOnly Property Frontwheel() As Wheel
Get
Return m_frontWheel
End Get
End Property
Public ReadOnly Property Rearwheel() As Wheel
Get
Return m_rearWheel
End Get
End Property
End Class
Public Class Wheel
Private ReadOnly m_spokes As SpokeCollection
Public Sub New()
m_spokes = New SpokeCollection
End Sub
Public ReadOnly Property Spokes() As SpokeCollection
Get
Return m_spokes
End Get
End Property
End Class
Public Class SpokeCollection
Inherits CollectionBase
Friend Sub New()
End Sub
Public Function Add(ByVal partNumber As Integer, _
ByVal allow As Integer) As Spoke
Dim spoke As New Spoke(partNumber, allow)
InnerList.Add(spoke)
Return spoke
End Function
Default Public ReadOnly Property Item(ByVal index As Integer) _
As Spoke
Get
Return DirectCast(innerlist(index), Spoke)
End Get
End Property
End Class
Public Class Spoke
Private m_partNumber As Integer
Private m_allow As Integer
Friend Sub New(ByVal partNumber As Integer, ByVal allow As Integer)
m_partNumber = partNumber
m_allow = allow
End Sub
Public Readonly Property PartNumber() As Integer
Get
Return m_partNumber
End Get
End Property
Public Readonly Property Allow() As Integer
Get
Return m_allow
End Get
End Property
Public Sub Adjust()
End Sub
End Class
Hope this helps
Jay