realbasic-nug
[Top] [All Lists]

Re: Class Interface help

To: REALbasic NUG <realbasic-nug at lists dot realsoftware dot com>
Subject: Re: Class Interface help
From: Joe Huber <joehuber at talasoft dot com>
Date: Sun, 30 Jul 2006 09:52:11 -0700
Cc:
Delivered-to: listarchive at realsoftware dot com
Delivered-to: realbasic-nug at lists dot realsoftware dot com
References: <FECDB7EF-D317-4159-9494-BED4D0BF6736 at kellerfarm dot com>
At 11:58 AM -0400 7/30/06, andrew at kellerfarm dot com wrote:
I'm looking for a tutorial on Class Interfaces, but I'm having trouble finding any up-to-date information on the web. Does anyone have any URLs or documentation, or is this something that can be discussed here?

Hi Andrew

Charles Yeomans has a good discussion of Class Interfaces on his web site.

  http://www.declaresub.com
  http://www.declaresub.com/Articles/ClassInterfaces/index.html

Understanding class interfaces themselves is pretty simple. It's an extra handle that you can use to refer to any class that implements a set of methods that you define in the Class Interface. The methods are defined in the interface, but are implemented in each of the classes.

A class is it's own type and constitutes it's set of public methods.

That same class can also implement one or more class interfaces. And each interface represents a separate type with it's own (sub)set of public methods. That interface gives you a separate handle as a way to reference that same class instance. The interface has a type that's the same as any other class implementing that interface, even if the class types themselves are different.

We always hear about how a class interface allows disparate object types to be treated the same through a common class interface they all implement. Cool enough.

But what I find even more useful is the ability to have an array of the class interface type. It can hold a reference to any type of object as long as that object type implements that class interface. So the interface is cool, but it lets you do even more cool things with collections of disparate objects even in a strongly typed language.

Class interfaces became very important to me when I realized that objects that implemented the class interface could be put in arrays, passed as parameters, returned from methods, based on their class interface type just like any other strongly typed object.

A class interface is way more than just an interface into a class. It's a way for a single class to have multiple types all at the same time. It's a way for a "ListBox" to also be a "Serializer" and a "Pickler" and a "DataPump" all at the same time. Very cool stuff.

Hope this helps,
Joe Huber
_______________________________________________
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>