473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Property procedures vs. fields

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
MCP (Visual Basic)
Fairfax, VA
Nov 20 '05 #1
3 1149
* "Andrew J. Marshall" <An*************@ObjectVision.netANTISPAMDEVICE> scripsit:
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?

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #2
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"

--
Rob Windsor [MVP-VB]
G6 Consulting
Toronto, Canada
"Andrew J. Marshall" <An*************@ObjectVision.netANTISPAMDEVICE> wrote
in message news:Ol**************@TK2MSFTNGP12.phx.gbl...
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
MCP (Visual Basic)
Fairfax, VA

Nov 20 '05 #3
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.
--
Andrew J. Marshall
MCP (Visual Basic)
Fairfax, VA

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
* "Andrew J. Marshall" <An*************@ObjectVision.netANTISPAMDEVICE>

scripsit:
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?

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>

Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Chrisbarbers | last post by:
--part1_108.256bef7d.2c5af59f_boundary Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: quoted-printable Hi =A0 I have purchased a package that uses ASP and SQL,...
3
by: Ryan.Chowdhury | last post by:
This is a general question regarding the use of view and stored procedures. I'm fairly new to databases and SQL. I've created a SQL database using an Access Data Project ("ADP") and I'm...
3
by: Johnny M | last post by:
using Access 2003 Pardon the subject line, but I don't have a better word for this strange behavior (or behavior I don't understand!!!) I have a class module named DepreciationFactor. One of...
1
by: shumaker | last post by:
IF I have a very simple query, something like SELECT COLUMNNAME FROM TABLE and I know I will use it at least in a few different places, then would it be good design to create a stored procedure...
13
by: Peter Kirk | last post by:
Hi there, can someone tell me what exactly a "property" is in a C# class? As far as I can see it is "two methods" - ie a getter and a setter for an instance variable. What is the difference...
62
by: djake | last post by:
Someone can explain me why to use property get and property set to access a value in a class, insted of access the value directly? What's the usefulness of property statements in VB.NET? Thanks
3
by: lemes_m | last post by:
Situation: Stored procedure 1 which is related with Stored procedure 2 which has parametar. Does anyone knows how to transfer value of some field from stored procedure 1 to parametar in stored...
6
by: Bob Darlington | last post by:
I want to use the caption property for fields in a recordset as a condition in a loop. That is, I only want to consider those fields which have captions: For each fld in RecordsetName.Fields If...
1
by: murtyin | last post by:
Hi to All, I am creating COM Wrappers(CCW's) to the existing .Net Product, which is developed using C#. In this, am getting problem with setting "Item" propertty as the Default Property. My...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.