Class Properties

  • Thread starter Thread starter Dave
  • Start date Start date
D

Dave

I was just wondering what the difference between using readonly properties
in a class definition instead of using a function?

Example:

Public Class myClass
Private privateValues() as Long
'
' do other stuff to initialize everything here
'
Public ReadOnly Property getPrivateLongValue_p(ByVal index as integer)
as Long
Get
return privateValues(index)
End Get
End Property
' versus
Public Function getPrivateLong_f(ByVal index as Integer) as Long
return privateValues(index)
End Function
End Class

This may not be a good example of a reason to use one over the other, but
was interested to know what the differences are?
 
as I understand it, property accessors are functions so go with what you
feel makes more logical sense for the user-devs.

-smith
 
Dave said:
I was just wondering what the difference between using readonly properties
in a class definition instead of using a function?

Classes represent entities.
Properties represent the entitiy's attributes.
Methods represent operations that can be performed by the entity.

So it's on the one hand a decision based on semantics. On the other hand,
the characeristics of the implementation should influence the decision.
Accessing a property should be "fast", there should not be long calculations
involved. Properties simply return the value of an attribute (sure, this
can include some calculation work or similar). Methods do some work before
returning in most cases.
 
There are a few differences that might prompt one to use a property instead
of a Method such as accessing class properties thru the PropertyDescriptor
Collection Class in the case of accessing classes with different properties
in a routine that doesn't know before hand what class will be passed to it as
an object.
 
Thanks to all who responded. Your explanations have helped me get a better
understanding and have been very helpful.

Dave
 
Back
Top