Re: Extending Methods Vs Delegates
- From: Sybren Stuvel <sybrenUSE@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 26 Mar 2006 13:18:28 +0200
vbgunz enlightened us with:
I hope I've made some sense with this question. I ultimately wish to
know just one real thing. Regardless of the name of the second
example above, what is the purpose of calling a sub class method
from a super class instance? What is the application to such a
design?
I've seen this style of programming before, in wxWidgets. The
constructor of a class does various things. This is roughly what
happens:
class wxSomeClass(wxParent):
def __init__(self, *args, **kwargs):
# Do various things
if not self.OnInit():
raise RuntimeError("Initialization failed")
# Do other things that need to be done after custom
# initialization
def OnInit(self):
return True
This makes it easier to simply provide custom initialization, without
having to redo everything in __init__. Calling the superclass'
function is fine if you want to add behaviour before and/or after
calling it. This example however lets you customize behaviour that's
put in the middle of the __init__ function.
Maybe an example will help?
I hope so :)
Sybren
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa
.
- References:
- Extending Methods Vs Delegates
- From: vbgunz
- Extending Methods Vs Delegates
- Prev by Date: Re: Extending Methods Vs Delegates
- Next by Date: Re: SSH, remote login, and command output
- Previous by thread: Re: Extending Methods Vs Delegates
- Next by thread: Using Dictionaries in Sets - dict objects are unhashable?
- Index(es):
Relevant Pages
|