Object structure question

  • Thread starter Thread starter Jon
  • Start date Start date
J

Jon

I have an object in my program that represents a movie. As part of that
objects properties, I would like to have the "cast" of the movie. I am not
sure whether I should simply make a public array variable to hold them or a
collection or even a property that is an array. I've never made a property
that was an array, so I'm not very sure how to declare it, if I were to use
it. Could someone push me in the right direction and offer a bit of advice?
Thank you
 
* "Jon said:
I have an object in my program that represents a movie. As part of that
objects properties, I would like to have the "cast" of the movie. I am not
sure whether I should simply make a public array variable to hold them or a
collection or even a property that is an array. I've never made a property
that was an array, so I'm not very sure how to declare it, if I were to use
it. Could someone push me in the right direction and offer a bit of advice?

What do you want to store in the cast "array"? Objects of a certain
type?

This code will create a property which returns an array:

\\\
Private m_Cast() As String

Public Property Cast() As String()
Get
Return m_Cast
End Get
Set(ByVal Value As String())
m_Cast = Value
End Set
End Property
///

I think it's better to use an 'ArrayList' or even better a type-safe
collection to store the items.
 
Jon said:
I have an object in my program that represents a movie.
As part of that objects properties, I would like to have the
"cast" of the movie. I am not sure whether I should simply make
a public array variable to hold them or a collection or even a
property that is an array.

Anything Public is uncontrolled (by your class) and, therefore,
inherently "dangerous". Somebody could do something like this:

Class Movie
Public Cast() as CastMember
. . .
End Class

BitOfFun = New Movie( "Terminator", 3 )
BitOfFun.Cast( 0 ) = New CastMember( "Charlie Chaplin" )

Perfectly valid, but I don't think the action sequences would be
quite the same. ;-)

It would be better wrap the [private] cast members (/however/
you choose to store them) with a [read-only] public property.

HTH,
Phill W.
 
Thanks for your answer. The array will be a listing of the name's of the
cast members of the movie. So, it will be several text objects.
 
* "Jon said:
Thanks for your answer. The array will be a listing of the name's of the
cast members of the movie. So, it will be several text objects.

Then a string array is a good solution if the data doesn't (often) change in the
lifetime of the object.
 
Back
Top