Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Class Question

Should class methods be declared as properties or as friend functons?

I know this is a little off excel topic. Could anyone recommend a general
newsgroup geared toward Visual Basic Program design


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,071
Default Class Question

As far as a VB program design group goes, I don't believe there is any.
You could try one of the VB / VB.Net groups or the developers.vba group.

As far as your specific question goes, the answer is neither. If it is
not a private sub/function, it can be accessed as a method, i.e.,
Object.Method

For example, suppose the class module, Class1 contains

Option Explicit

Sub x()
MsgBox "In x"
End Sub
Function y(x)
y = x ^ 2
End Function

Then, one could use it with code in a standard module as

Option Explicit

Sub testIt()
Dim x As New Class1
x.x
MsgBox x.y(2)
End Sub

Though, I might be inclined to make y a property.

--
Regards,

Tushar Mehta
MS MVP Excel 2000-2003
www.tushar-mehta.com
Excel, PowerPoint, and VBA tutorials and add-ins
Custom Productivity Solutions leveraging MS Office


In article ,
says...
Should class methods be declared as properties or as friend functons?

I know this is a little off excel topic. Could anyone recommend a general
newsgroup geared toward Visual Basic Program design



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 459
Default Class Question

I can recommend the following article:

The Basics of Programming Model Design
Dave Stearns
Microsoft Corporation, June 1998
http://msdn.microsoft.com/library/de...n_basicpmd.asp

Of particular relevance is the chapter, 'When to Use Properties vs.
Methods', so I'll quote some of it he

"The first question people will often ask me is, "When should I make
something a property and when should I make it a method?" Note that in
COM everything is really a method. Properties are always just a pair
of get and set methods that have been marked as a property in the
Interface Description Language (IDL). For Microsoft Visual Basic
developers, this is accomplished by using Property Get and Property
Let/Set procedures instead of functions and subroutines. When the
developer marks something as a property, Automation clients such as
Visual Basic and Visual Basic Scripting Edition (VBScript) can then
refer to that as if it were a data member of the object, but code is
always run in the class. In fact, if you just mark a class-level
variable in your Visual Basic class as Public, Visual Basic
automatically creates a simple set of property procedures for you.

"To determine if something should be a property or method, use the
following rules:

• Anything that reflects a state of the object should be exposed as a
property. Examples include Caption, Opened, or Visible.

• If the object state is read-only, it should still be exposed as a
property but should be read-only (that is, it does not include a
propput or, in Visual Basic, a Property Let/Set procedure). Examples
might include hWnd, hDC, or WindowStyle.

• If getting a value has no real side effect on the object, it's
likely a property and not a method. A property get can involve code
that retrieves something from a data source the first time it's
requested, but that should be hidden from the developer using the
interface.

• Similarly, getting a property's value should not be order-dependent.
It should make no difference if you get the value of property A and
then B, or vice versa.

• Anything that performs an action and has no real "property get"
meaning should be a method. Examples here include Open, Save, Export,
Add, and Remove. If the method is directly affecting a state that
would be valuable for a developer to also be able to read, it's
probably a property and not a method.

"This last point is important. I have often designed something as a
method first and then later realized that it also would be useful to
get the value of the state affected by the method. This sometimes
means turning the method into a Read/Write property, and other times
just means adding a Read-only property that is affected by the
existing method call. The right choice depends on your design style
and what you are trying to expose to the developer."

--

"John T Ingato" wrote in message ...
Should class methods be declared as properties or as friend functons?

I know this is a little off excel topic. Could anyone recommend a general
newsgroup geared toward Visual Basic Program design

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Chart Class Module/follow on question to hyperlink post earlier. Rominall Charts and Charting in Excel 2 March 7th 07 02:43 AM
how do I set up a workbook for a class Des New Users to Excel 2 May 9th 05 05:58 PM
Class Modules Siphuncle Excel Programming 2 August 12th 03 06:37 PM
form class jim c Excel Programming 1 July 30th 03 07:25 AM
CommandBarControl class John A Grandy Excel Programming 2 July 19th 03 07:42 PM


All times are GMT +1. The time now is 08:08 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"