[Pyobjc-dev] Mixin classes
Brought to you by:
ronaldoussoren
|
From: Johan R. <joh...@gm...> - 2009-05-05 14:38:10
|
I'm trying to implement the informal NSKeyValueBindingCreation protocol.
I would love to make it a mixin-class so I can reuse the functionality
throughout
my application.
Here's how I planned to do it:
class NSKeyValueBindingCreation:
def bind_toObject_withKeyPath_options_(self, binding, anObject,
keyPath, options):
...
def observeValueForKeyPath_ofObject_change_context_(self, keyPath, anObject,
change, context):
....
class Foo(NSObject, NSKeyValueBindingCreation):
....
The problem is that my Foo class won't recognize the
observiceValueForKeyPath:ofObject:change:context: message.
objc.error: NSInternalInconsistencyException - <Foo: 0x35e430>: An
-observeValueForKeyPath:ofObject:change:context: message was received
but not handled.
If I put it directly in Foo it gets recognized.
Poking through the PyObjC manual I found the following lines:
Multiple inheritance may be used when subclassing an Objective-C
class, so long as the Objective-C class is the first base class and there
is only one Objective-C base class. The Objective-C runtime does not
support multiple inheritance. These mix-in classes should not contain
different implementations for Objective-C methods. To achieve this
behavior, Categories should be used instead.
I interpret those lines as that the snippets above should work.
Am I wrong?
How can I, and how should I use mixin classes?
|