Property procedures vs. fields

  • Thread starter Thread starter Andrew J. Marshall
  • Start date Start date
A

Andrew J. Marshall

If I have a class Fool with an attribute Bark implemented as a field

Public Class Fool
Public Bark As Boolean
End Class

and I want to "upgrade" it to be implemented as a property procedure

Public Class Fool
Protected MyBark As Boolean
Public Property Bark() As Boolean
Get
Return Me.MyBark
End Get
Set(ByVal Value As Boolean)
Me.MyBark = Value
End Set
End Property
End Class

, will this cause any problems for consumers of my class?
 
* "Andrew J. Marshall said:
Public Class Fool
Public Bark As Boolean
End Class

and I want to "upgrade" it to be implemented as a property procedure

Public Class Fool
Protected MyBark As Boolean
Public Property Bark() As Boolean
Get
Return Me.MyBark
End Get
Set(ByVal Value As Boolean)
Me.MyBark = Value
End Set
End Property
End Class

, will this cause any problems for consumers of my class?

What problems would you expect? Changing the interface of the class?
 
Andrew,

The "upgraded" (using property procedure) version is the preferred (best
practice) method. Also, in certain cases you cannot data bind to a public
field so you need to implement a property procedure.

Just a note, the suggested naming convention for your protected field would
be "_bark"
 
Yes, an interface/binary compatibility issue. The object browser seems to
know if an attribute was coded as a field or a property, and that made me a
little nervous.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top