Re: [Pyobjc-dev] Mixin classes
Brought to you by:
ronaldoussoren
From: Ronald O. <ron...@ma...> - 2009-05-07 05:33:36
|
Johan, On 5 May, 2009, at 16:37, Johan Rydberg wrote: > 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? Yes ;-) > > How can I, and how should I use mixin classes? You cannot do this at the moment. Mixins cannot be used to add new methods that the ObjC runtime will see. I might add this behaviour in the future, I like your usecase and this could be used to make useful common functionality available as mixin classes. Adding this will require a detailed specification and testsuite, the objc runtime doesn't support multiple-inheritance itself and hence support for mixin classes will require some tricks. I'm especially worried about getting the semantics exactly like they'd be if the base-class is a regular Python class. Ronald > > ------------------------------------------------------------------------------ > The NEW KODAK i700 Series Scanners deliver under ANY circumstances! > Your > production scanning environment may not be a perfect world - but > thanks to > Kodak, there's a perfect scanner to get the job done! With the NEW > KODAK i700 > Series Scanner you'll get full speed at 300 dpi even with all image > processing features enabled. http://p.sf.net/sfu/kodak-com > _______________________________________________ > Pyobjc-dev mailing list > Pyo...@li... > https://lists.sourceforge.net/lists/listinfo/pyobjc-dev |