On Mar 9, 2006, at 4:29 PM, Theodore H. Smith wrote:

At 2:19 PM -0600 3/9/06, Guyren Howe wrote:

But for those keeping score at home: no-one has offered an example
of class extension, other than the couple of corner cases I cited,
where the results are clearer/easier to write/easier to
maintain/anything else convincing, using method overriding rather
than Events.

I have a demo project called TinyXML. It's a small toolkit for parsing/rendering XML, it also validates XML well-formedness to the XML 1.0 spec. I wrote it purposely in a very small amount of code. It's also much faster than RB's parser, although it uses an incompatible API and doesn't offer much "power features". It's a demo project, basically. The fact that I use it for real world purposes is just a sign of how good a demo it is :)

Anyhow, TinyXML basically builds it's XML document structure, out of two classes. There is TXText, and TXElement. TXElement is a subclass of TXText.

TXText has a method "FSRender". TXElement overrides FSRender.

So, to render my XML, I can just call FSRender(Some params here).

This is much neater than using events. With an event, I'd need to check if I am a TXText or not before actually calling the event, or just check if the event returned a special return code which said "yes this event is implemented".

Actually, a fairly useful Object Oriented Design heuristic is to only make instances of your leaf classes. IOW, all non-leaf classes should be abstract.

Employing that heuristic here removes your concerns. In this case, you could happily have an abstract superclass, that handed down the FSRender call in an event to two separate subclasses. The shared functionality would go in the superclass, the differences would go in the subclasses. The result would, to my mind, be clearer (Events having the advantage of being much more self-documenting).

This way, all you see in code is FSRender. Like this:

for i = 0 to n
  me.Child(i).FSRender( fs )
next

No reason that an implementation using Events should not work like this.

In fact there are many good examples for over riding. I think a good book on OOP should be able to give you some concrete examples, as I don't have the time to think of them all. There was this book by Betrand Meyer...

Events are unique to REALbasic, so advice about OOP in other languages won't help us with the question at hand, which is whether I am correct in my contention that Events are, except a couple of corner cases, best practice for class extension in REALbasic. Andrew Barry (the original author of REALbasic, and the inventor of the Events extension system) certainly thought so. He originally did not intend to have overriding at all, and only added overriding to make porting software easier.

Guyren G Howe
guyren-at-relevantlogic.com
http://relevantlogic.com

REALbasic, PHP, Python programming
PostgreSQL, MySQL database design and consulting
Technical writing and training


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

Reply via email to