From: "Joseph J. Strout" <[EMAIL PROTECTED]>
Date: Thu, 9 Mar 2006 13:37:53 -0700
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".
This way, all you see in code is FSRender. Like this:
for i = 0 to n
me.Child(i).FSRender( fs )
next
And it does just that, it renders the XML into the string buffer "fs".
In fact I rarely use events OR override, I prefer to "compose".
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...
_______________________________________________
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>