472,799 Members | 1,750 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Readonly property vs function

With a Class is there any difference between a readonly property and
function besides having to use Get/End Get.
Are there any performance/resource advantages for either.

Thanks
Fred
Nov 20 '05 #1
5 10184
Hi,

With a function you can pass in arguments and calculate a result. A
readonly property only returns a value.

Ken
---------------------
"fred" <fr**@NoSpam.com> wrote in message
news:u8**************@TK2MSFTNGP09.phx.gbl...
With a Class is there any difference between a readonly property and
function besides having to use Get/End Get.
Are there any performance/resource advantages for either.

Thanks
Fred

Nov 20 '05 #2
Surely, I can have arguments on a property and calculate a result

Public Readonly Property Calc(ByVal X as integer, ByVal Y as integer) as
long
Get
Return X * Y
End Get
End Property
"Ken Tucker [MVP]" <vb***@bellsouth.net> wrote in message
news:OJ**************@tk2msftngp13.phx.gbl...
Hi,

With a function you can pass in arguments and calculate a result. A readonly property only returns a value.

Ken
---------------------
"fred" <fr**@NoSpam.com> wrote in message
news:u8**************@TK2MSFTNGP09.phx.gbl...
With a Class is there any difference between a readonly property and
function besides having to use Get/End Get.
Are there any performance/resource advantages for either.

Thanks
Fred

Nov 20 '05 #3
Fred,
With a Class is there any difference between a readonly property and
function besides having to use Get/End Get. I normally use properties for a 'value' or 'attribute' a noun, something
that describes the object. (I'm using attribute here to mean an OO
attribute, not a System.Attribute class)

I normally use functions for 'actions' or 'behavior' a verb, something that
the object does.

Also you can using data binding to bind to a property, while you cannot bind
to a function.
Are there any performance/resource advantages for either. Not really as a Property is effectively a function in the IL.

I find it better to write "correct" programs then to worry about
performance. By "correct" I mean OO and use the correct tool for the correct
job (for example: a property for attributes and functions for
behavior/actions). Remember that most programs follow the 80/20 rule (link
below) that is 80% of the execution time of your program is spent in 20% of
your code. I will optimize
the 20% once that 20% has been identified & proven to be a performance
problem via profiling (see CLR Profiler in my other message).

For info on the 80/20 rule & optimizing only the 20% see Martin Fowler's
article "Yet Another Optimization Article" at
http://martinfowler.com/ieeeSoftware...timization.pdf

Hope this helps
Jay
"fred" <fr**@NoSpam.com> wrote in message
news:u8**************@TK2MSFTNGP09.phx.gbl... With a Class is there any difference between a readonly property and
function besides having to use Get/End Get.
Are there any performance/resource advantages for either.

Thanks
Fred

Nov 20 '05 #4
Curiously, the VB compiler doesn't hurl on this code, although it does
violence to the distinction between properties and methods.

Object-oriented theory considers a property to be a representation of some
notion of the state of an object, and a method (function or, in VB, sub) to
represent some behavior of the object that the method carries out.

A property may be simply a means of exposing the value of a state variable,
such as a string or numerical value held in the object's instance memory, or
it may be a transformation or calculated result based on the state of the
object. For example, you might have a Temperature class, with properties
named Fahrenheit and Centigrade. The class holds a single data field
containing the temperature value (in a representation that's no one's
business but that of the class - maybe it's in Kelvin), but returns the temp
in Fahrenheit or Centigrade by performing a calculation on the internal
temperature value.

By convention, a class that contains a list or collection of other objects
may expose an indexed property like Item, where a single input argument
represents the index in the contents, and the return value of the property
is the object at that location in the collection. This is about the only
parameterized property that the theorists approve of.

So, in general, properties don't have arguments, except for indexers.
Functions and (in VB) Subs may or may not, depending on their design.

HTH,
Tom Dacon
Dacon Software Consulting
Surely, I can have arguments on a property and calculate a result

Public Readonly Property Calc(ByVal X as integer, ByVal Y as integer) as
long
Get
Return X * Y
End Get
End Property

Nov 20 '05 #5
Yea, the IDE will constantly call your Get method.

As a general rule, you should be able to call a Property Get multiple times
with no side-effects. If the method actually does something, then use a
function.

--
Jonathan Allen
"fred" <fr**@NoSpam.com> wrote in message
news:u8**************@TK2MSFTNGP09.phx.gbl...
With a Class is there any difference between a readonly property and
function besides having to use Get/End Get.
Are there any performance/resource advantages for either.

Thanks
Fred

Nov 20 '05 #6

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

Similar topics

4
by: Moe Sizlak | last post by:
Hi There, I am trying to use the to obtain the information from 2 listmenus, if the user makes a selection the page is submitted and then based on the value selected is transfererd to another...
10
by: GP | last post by:
Is it possible to iterate through all the controls collection and make the textboxes alone as read only.I don't see a readonly property for the Control.Can some one help me in this context? I...
0
by: Brian Young | last post by:
Hi all. I'm using the Property Grid control in a control to manage a windows service we have developed here. The windows service runs a set of other jobs that need to be managed. The control...
7
by: DareDevil | last post by:
I have written a method that should modify the folder path passed to it into one that exists and is selected by the user. It then returns a boolean depending on whether a folder path was selected by...
3
by: Moe Sizlak | last post by:
Hi There, I am trying to use the to obtain the information from 2 listmenus, if the user makes a selection the page is submitted and then based on the value selected is transfererd to another...
2
by: miben | last post by:
I need to set a variable returned by a readonly property in a class by another class. So the only way to set that value is from a specific class and function. Public Sub Main Dim setter As New...
12
by: eric.goforth | last post by:
Is there any reason to use: Private newPropertyValue As Integer Public ReadOnly Property MyProperty(ByRef MyParam as Integer) As Integer Get Return newPropertyValue End Get End Property
3
by: Hamed | last post by:
Hello I have a DataGrid object in my ASP.NET page that has the following template column. When I put the "readonly" attribute in the INPUT tag, it generates readonly="". <asp:TemplateColumn...
0
by: Tom Dacon | last post by:
Oops, what I gave you in my first response was the usual way that you use varying scope: Private _FieldValue As <some type> Public Property Something As <some type> Get Return _FieldValue...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.