realbasic-nug
[Top] [All Lists]

Re: Subclassing Question

To: REALbasic Network Users Group <realbasic-nug at lists dot realsoftware dot com>
Subject: Re: Subclassing Question
From: "Joseph J. Strout" <joe at realsoftware dot com>
Date: Thu, 22 Aug 2002 06:45:11 -0700
At 10:26 AM +0100 8/22/02, Steve Thomas wrote:

Since class2 is a subclass, the two are type-compatible, so syntactically
and semantically everything is fine. However, I can't find a way of
instantiating a new object of the same subclass as the current object, from
code within the superclass.

You can't. You need to make a NewSameType method, which is overridden by each subclass to return a new instance of that class.

I can think of a workaround, which uses a virtual method NewObject(), which
returns a new instance, which is overridden in each subclass to instantiate
a member of that subclass.

I see we're on the same wavelength!

Cheers,
- Joe

--
,------------------------------------------------------------------.
|    Joseph J. Strout           REAL Software, Inc.                |
|    joe at realsoftware dot com       http://www.realsoftware.com        |
`------------------------------------------------------------------'


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