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: Will Leshner <leshner at ljug dot com>
Date: Thu, 22 Aug 2002 07:16:26 -0700
Requiring an override of NewObject is very elegant and is exactly the way you should do things. Especially it is very inelegant to have a super class know about its subclasses. Otherwise you'd have to change your super class every time you or somebody else creates a new subclass. You probably should make a super class that returns NIL for NewObject. That way if somebody forgets to override they will find out pretty quickly.

On Thursday, August 22, 2002, at 02:26  AM, Steve Thomas wrote:

NewObject=new me.type

Within the superclass function, to create a new object of whatever type the
reference actually is.

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. This would work fine except for the following
issues:

1) The I am not the only person who will be subclassing this class. If I make the class dependent on having an overridden method and somebody else fails to override it, it could cause problems in the application. I also can't think offhand of a way of flagging whether or not the method has been
overridden, to generate meaningful errors if this were the case.

2) This is a messy and inelegant way of doing it and I don't like writing
messy and inelegant code.



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