?
Solved

Property or Method -- Which is Which

Posted on 2003-03-18
11
Medium Priority
?
214 Views
Last Modified: 2013-11-25
We have created many controls in the past, but recently we created a new ActiveX DLL and are having "religious" debates on whether some things are Properties or Methods. Our DLL has a collection of datapoints in it. It also keeps track of an external reference clock, among other things. The following are only a few examples. For each of the following, would it be a Property or a Method:

1) PointIndex(Name): PointIndex() is passed a name and returns an index.

2) AllNames(): returns a list of all the names in the collection.

3) PointCount(): returns the number of points in the collection.

4) SubscribePoint(Name): adds name to list so that the named point is constantly monitored.

5) PointValue(Name): reads the value of a named point.

6) WritePointValue(Name, Value): writes the value of a named point.

7) ReadPointValue(Name): reads the value of a named point.

8) Date(): reads or writes the date.

There may be multiple sets of points awarded, depending on the feedback.
0
Comment
Question by:GivenRandy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 400 total points
ID: 8158901
Hi GivenRandy,

I guess it could well be a "religious" debate!

My opinion such as it is goes like this:

4 and 6 are methods, the rest are properties.

I would categorise a method as routine which takes zero or more arguments and executes one or more related actions as a result. Optionally this may return a value indicating the result of the action(s).

A property is a routine which sets or retrieves information within the component.

Tim Cottee MCSD, MCDBA, CPIM
http://www.timcottee.tk 

Brainbench MVP for Visual Basic
http://www.brainbench.com

Experts-Exchange Advisory Board Member
0
 
LVL 5

Expert Comment

by:JohnMcCann
ID: 8158933
Thisa is only my opinion

1) PointIndex(Name): Property
2) AllNames(): Property
3) PointCount(): Property
4) SubscribePoint(Name): Method

5, 6 and 7 all the same property
5) PointValue(Name):
6) WritePointValue(Name, Value):
7) ReadPointValue(Name):

8) Date(): Property
0
 
LVL 3

Expert Comment

by:DocM
ID: 8158938
SubscribePoint(Me)
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 5

Expert Comment

by:JohnMcCann
ID: 8158958
Just to clarify why 5,6 and 7 are the same property

Public Property Get PointValue(Byval strName as String) as String

Public Property Let PointValue(Byval strName as String, strValue as String)


5) PointValue(Name):              Property Get PointValue
6) WritePointValue(Name, Value):  Property Let PointValue
7) ReadPointValue(Name):          Property Get PointValue

0
 
LVL 43

Expert Comment

by:TimCottee
ID: 8158971
John,

I can agree with you in principle and you could argue that in fact 5 and 7 are indeed duplicates. 6 could be either a method or a property and perhaps on reflection is indeed that rather than a method.
0
 
LVL 9

Author Comment

by:GivenRandy
ID: 8158996
>I would categorise a method as routine which takes zero
>or more arguments and executes one or more related
>actions as a result. Optionally this may return a value
>indicating the result of the action(s).

That is very close to the definition that I use. Some say that any time you pass an argument (at all), it is required (!) to be a method. For example, #5 would have to be a Method under that definition:

lngSomeResult = X.Value(SomeName)

However, it gets interesting, as even your breakdown illustrates. Let's suppose we are writing the value. Here are two cases, using the above:

#5:  X.PointValue(SomeName) = 23.5
#6:  X.WritePointValue SomeName, 23.5

You would make #5 a Property while #6 would be a Method. I tend to agree with you. I think it is somewhat silly to automatically list something as a Method simply because it has arguments -- a method implies "doing something".
0
 
LVL 9

Author Comment

by:GivenRandy
ID: 8159010
Er (dang, cannot edit comment), #6 is more like a property and probably should be changed to look like a property (e.g., use "PointValue" as read/write instead of having "WritePointValue").
0
 
LVL 9

Author Comment

by:GivenRandy
ID: 8159034
What about a case where the function may return an array of values. For example, requesting a name will return a 10-element array of values -- requesting (ByVal) SomeName returns (via ByRef) the array into SomeArray:

X.ReadPoint(SomeName, SomeArray)

Is that still a Property or has it morphed into a Method?
0
 
LVL 5

Expert Comment

by:JohnMcCann
ID: 8159110
I'd still say a property, on the grounds that SomeName and SomeArray map to variables of your class.  A method should invloke some action e.g. paint, draw create, destroy, load, unload.  A property on the other hand should map to states and state data within the class.  Thus changing a property value should alter te state or state data of your class.  The obvious exception is a method that manipulates numerous state data values as in read/write properties.
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 8160547
According to the latest Java standards, which seems to be what MS is paralleling with .Net, there really are no properties anymore.  

All "properties" are really just public variables, and exposing variables seems to cause too many problems.  Rather, all variables are simply private areas of the object that can be set/retrieved via methods.

Ex.
Rather than:
   property myValue
you get two methods:
  sub setMyValue(Value as Object)
and
  function getMyValue() as Object

That said, the general rule is that if the thing is a storage area, it's a property; if it's an action, it's a method.

By looking at your names, 4 has an action built into the names and is therefore probably a method; 5 to 7 may have actions attached to them so they MAY be methods; the others seem to be storage areas and are essentially properties.  Also, based on the description, #8 may be a method, but based on the name it may be a property.
0
 
LVL 9

Author Comment

by:GivenRandy
ID: 8173646
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month9 days, 19 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question