realbasic-nug
[Top] [All Lists]

Re: Scope/Protection Question

To: REALbasic NUG <realbasic-nug@lists.realsoftware.com>
Subject: Re: Scope/Protection Question
From: Joe Strout <joe@inspiringapps.com>
Date: Sun, 31 May 2009 18:59:34 -0600
Authentication-results: mx.google.com; spf=neutral (google.com: 74.124.194.228 is neither permitted nor denied by best guess record for domain of realbasic-nug-bounces@lists.realsoftware.com) smtp.mail=realbasic-nug-bounces@lists.realsoftware.com
Delivered-to: listarchive@realsoftware.com
In-reply-to: <33CC0DC1-9A35-470C-9F05-B41262617C2A@satx.rr.com>
Organization: Inspiring Applications, Inc.
References: <345AFE42-338C-4588-9F76-7560C88B8609@verizon.net> <671647DA-EC14-41EB-A175-5289BBC5E0E3@satx.rr.com> <4A2197C1.1030809@inspiringapps.com> <5EAEA20D-BC8B-490D-8384-C965258AECF7@satx.rr.com> <4A21F411.70802@inspiringapps.com> <33CC0DC1-9A35-470C-9F05-B41262617C2A@satx.rr.com>
Reply-to: REALbasic NUG <realbasic-nug@lists.realsoftware.com>
Sender: realbasic-nug-bounces@lists.realsoftware.com
User-agent: Thunderbird 2.0.0.21 (Macintosh/20090302)
William Squires wrote:

No, a shared class method should only be able to access a shared class property, not an instance variable of a specific instance of that class. After all, it has no knowledge of a specific instance (that's the whole point), so how could it access an instance variable?

It gets a reference to it.  For example, here's a typical factory function:

Shared Function GetWidget(farble As Integer) As Widget
  // Return the Widget for the given farble, creating it
  // if necessary.
  Dim out As Widget = sWidgetMap.Lookup(farble, nil)
  if out is nil then
     out = New Widget  // note: the Widget constructor is protected!
     sWidgetMap.Value(farble) = out
  end if
  out.mGotCount = out.mGotCount + 1  // mGotCount is protected too
  return out
End Function

This is all perfectly valid and reasonable, and in fact is a common idiom: you make the constructor protected, so that it can't be created
from outside the class, and then add a shared function which CAN create
it, but only on terms you specify. (As in the above example, where it creates a new one only if it doesn't have one already ready to do the requested job.)

If you want a method of some class to be able to access a protected or private instance variable of an instance of some other class, then that class needs to expose it through an accessor method, or a non-default constructor.

Nope.

The quirk that Karen found is that, if the static type of the reference is a subclass rather than the base class, code in the base class is not being allowed access to the base class privates. And THAT is the bug (or at best, design flaw).

I assume the code in question isn't in an overridden subclass method? If so, then I would say that's a bug.

Right, it was in a base class method.

Best,
- Joe

--
Joe Strout
Inspiring Applications, Inc.
http://www.InspiringApps.com


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

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>


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