realbasic-nug
[Top] [All Lists]

Re: Interfaces and Computed Properties

To: REALbasic NUG <realbasic-nug@lists.realsoftware.com>
Subject: Re: Interfaces and Computed Properties
From: Michael Diehr <md03@xochi.com>
Date: Wed, 26 Nov 2008 14:26:32 -0800
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: <1ED2BB86-1E43-4A4C-8245-F8D587E28BC2@great-white-software.com>
References: <4F4D1ADF-52CE-4EBA-9346-9BE37992CCDD@xochi.com> <1ED2BB86-1E43-4A4C-8245-F8D587E28BC2@great-white-software.com>
Reply-to: REALbasic NUG <realbasic-nug@lists.realsoftware.com>
Sender: realbasic-nug-bounces@lists.realsoftware.com
On Nov 26, 2008, at 12:47 PM, Norman Palardy wrote:

On 26-Nov-08, at 1:17 PM, Michael Diehr wrote:

Let's say you have an interface, and one of the items in it is really a property. It seems that a class implementing the interface can't have a property with the same name as the interface method (this makes sense, I think). However I'm wondering if there's a clean way to accomplish this using computed properties, or 'assigns' or similar? To rephrase my question -- can Interfaces only describe Methods, or can they describe Properties as well?

Methods only
They do not specify HOW to implement something just the API that will be adhered to
A property of any kind is an implementation detail

Ok, that's fair.

Here's my specific problem: I'm trying to create an interface that is applied to a Window, a plugin class, and a user-defined class. I'd like the interface to have a "Visible as boolean" getter. It seems that the Interface won't recognize methods that are inherited
from a superclass (e.g. if I add an interface containing "Visible as
boolean" to a window, I get the "class is missing a method " error.

So, thinking I'd be clever, I just tried to add
  function Visible as boolean
    return me.visible
to the window.

This of course, doesn't work, as it causes a stack overflow since "method visible" is shadowing "property visible". I tried "return super.visible" but that didn't work either (I think because window classes are not really subclasses?)

I ended up punting and renaming the interface to "IsVisible() as boolean" along with

function IsVisible as boolean
  return me.visible

which works, but seems inelegant.

I'm just wondering if there is a more elegant way to handle this : How best to add an interface to an object if the interface method name conflicts with a property of the class?


_______________________________________________
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>