realbasic-nug
[Top] [All Lists]

Re: Method vs Property

To: REALbasic NUG <realbasic-nug at lists dot realsoftware dot com>
Subject: Re: Method vs Property
From: Norman Palardy <npalardy at great-white-software dot com>
Date: Sat, 30 Sep 2006 09:34:18 -0600
Delivered-to: listarchive at realsoftware dot com
Delivered-to: realbasic-nug at lists dot realsoftware dot com
References: <20060929170038 dot 743DC153AF65 at lists dot realsoftware dot com> <1108DAEC-0D85-44AB-9D29-3F123622D610 at mac dot com>

On Sep 30, 2006, at 12:05 AM, Robert Livingston wrote:

When is something a property and when a method?

Take the ListBox class as described in the LR


Cell is said to be a method

ListBox1.Cell(1,2) = "Dog"



CellType is said to be a property

ListBox1.CellType(1,3) = True



The syntax of their use seems to be the same. What makes one a property and the other a method? Its seems strange to me that you can assign a value to a method. (ListBox1.Cell(1,2) = "Dog")

Part of the trick is that you can make a method appear to be a property
It's actually one of the things that is very handy about RB

Suppose you has your own class, Foo, and you started out with it like


        Class Foo
                public property bar as integer
                public property baz as string

and you use it for a while and find that when you set the value for bar you wanted to do something
You could do the following

        Class Foo
                private property mybar as integer
                public property baz as string

                public method bar() as integer
                        return mybar

                public method bar(assigns v as integer)
                        mybar = v
                        baz = str(mybar)

Now, in the rest of your program NOTHING else had has to change, but bar is now a method, not a property but it's behavior is as though it's a property

You could have done the same with a computed property which is more like a method than an outright property


_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>


From  Sat 30 Sep 2006 09:34:52 -0600
Return-Path: <realbasic-nug-bounces at lists dot realsoftware dot com>
X-Original-To: listarchive at realsoftware dot com
Delivered-To: listarchive at realsoftware dot com
Received: by xmail.realsoftware.com (Postfix, from userid 1037)
        id 0612BCAED27; Sat, 30 Sep 2006 08:35:11 -0700 (PDT)
X-Spam-Checker-Version: SpamAssassin 3.1.1 (2006-03-10) on realxserve.local
X-Spam-Level: X-Spam-Status: No, score=-0.6 required=4.5 tests=AWL,NO_REAL_NAME autolearn=disabled version=3.1.1
Received: from lists.realsoftware.com (lists.realsoftware.com [209.198.132.125])
        by xmail.realsoftware.com (Postfix) with ESMTP id 52157CAED20;
        Sat, 30 Sep 2006 08:35:10 -0700 (PDT)
Received: from lists.realsoftware.com (localhost [127.0.0.1])
        by lists.realsoftware.com (Postfix) with ESMTP
        id 4C5811540C17; Sat, 30 Sep 2006 10:35:00 -0500 (CDT)
X-Original-To: realbasic-nug at lists dot realsoftware dot com
Delivered-To: realbasic-nug at lists dot realsoftware dot com
Received: from mail.verex.com (unknown [66.116.103.197])
        by lists.realsoftware.com (Postfix) with ESMTP id DB9471540C09
        for <realbasic-nug at lists dot realsoftware dot com>;
        Sat, 30 Sep 2006 10:34:52 -0500 (CDT)
Received: from [66.116.103.197] (localhost [127.0.0.1])
        by mail.verex.com (Postfix) with SMTP id 5469E655F08
        for <realbasic-nug at lists dot realsoftware dot com>;
        Sat, 30 Sep 2006 09:34:52 -0600 (MDT)
Date: Sat, 30 Sep 2006 09:34:52 -0600
From: joe at strout dot net
To: REALbasic NUG <realbasic-nug at lists dot realsoftware dot com>
In-Reply-To: <001648E8-1C77-4A7B-8439-855375805D94 at mobleybros dot com>
X-Mailer: VerEx Email Gateway
Content-type: text/plain;
Content-transfer-encoding: 7bit
Message-Id: <20060930153452 dot 5469E655F08 at mail dot verex dot com>
Subject: Re: How do you sort Object arrays?
X-BeenThere: realbasic-nug at lists dot realsoftware dot com
X-Mailman-Version: 2.1.2
Precedence: list
Reply-To: REALbasic NUG <realbasic-nug at lists dot realsoftware dot com>
Sender: realbasic-nug-bounces at lists dot realsoftware dot com
Errors-To: realbasic-nug-bounces at lists dot realsoftware dot com

On Sep 30, 2006, at 15:12 UTC, Phil M wrote:

Actually, I have it working without a wrapper object. I posted this technique earlier, but I provide a little more detail here.

Yes, something like this is what I usually do too.  However, a minor
performance nitpick: when building the array of sort keys...

     Dim v() As String
     Dim k, nilCount As Integer
     Do Until (k > UBound(f))
       If (f(k) Is Nil) Then
         f.Remove(k)
         nilCount = nilCount + 1
       Else
         v.Append(f(k).Name)     // get the property value here
         k = k + 1
       End If
     Loop

It'd be simpler and faster to preallocate the array, leave nil objects
in the original, and just treat these as if they have some value (for
strings, the empty-string would be a sensible choice IMHO).  So I would
do:

 Dim v() As String
 Redim v( UBound(f) )
 for k As Integer = 0 to UBound(f)
   v(k) = f(k).Name
 next

My $0.02 anyway,
- Joe

--
Joe Strout -- joe at strout dot net
Verified Express, LLC     "Making the Internet a Better Place"
http://www.verex.com/

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>


<Prev in Thread] Current Thread [Next in Thread>