On Monday 25 March 2002 03:51 pm, Jeffrey P Shell wrote:
> An interesting design example is the Cocoa frameworks of Mac OS X
> (and also the Enterprise Objects Framework, one of the finest
> object-relational persistence frameworks around).  Cocoa makes heavy
> use of "Delegates", objects which get attached to instances that
> implement a certain interface. A delegate for a Window might be asked
> "can this window be closed now?", or be warned that a certain window
> is about to be closed.  It's basically an interesting way of event
> handling, allowing a programmer to customize the behavior of the
> "Close" widget for his/her application without having to subclass
> NSWindow.  It may sound like a small thing, but it's actually quite
> significant.  An example out of the Enterprise Objects Framework is
> from the EUDatabaseContext delegate, which gives fine grained control
> over how a primary key is generated, how and if objects are locked,
> etc.  In theory, with MiddleKit, I can write my own delegate
> implementing my businesses primary key needs and use whichever
> database adapter I want, and do it all through aggregation, maybe
> even through a configuration file.

I used NeXTstep quite a bit and was also a big fan of delegation. 
However, in Python, I find it much more useful to have generic 
callbacks because the person who sets them can pass them in a variety 
of forms very easily:
        - a function: foo
        - a method of an object: self.foo  or  obj.foo
        - a class: Foo

e.g., anything callable. That's more flexible than the delegation 
approach where a single object had to handle all situations always via 
methods.

The Python technique for making the call back is simple:
        if self.didDisplayCallback:
                self.didDisplayCallback(self)


> An interesting thing might be to find or implement a decent Jython
> servlet and compare it to an identical-functionality servlet in
> Webware.  It would show a good contrast of the API's without getting
> stuck in language semantics.  To try to force myself to learn WebKit
> Servlet/PSP programming, I tried doing a Python interpretation of a
> co-workers Java servlet system, but got bogged down at points with
> language differences (particularly Java's ability to call different
> methods with the same name but different argument signatures).

Languages and frameworks are better used on their own terms. Rather 
than trying to port the innards, port the outtards. e.g., look at the 
application and implement it in frameworks A, B and C in the way that 
those frameworks would normally be used. Then compare the results. That 
will give you a more accurate feel for the products.

BTW You can do some "overloading" in Python as well:

import types

        def dumpFile(self, fileOrName):
                if isinstance(fileOrName, types.StringType):
                        fileOrName = open(fileOrName, 'r')
                print fileOrName.read()
                fileOrName.close()

I normally only do that when certain arguments can be logically 
transformed or "normalized" into the form that I really wanted in the 
first place. I first normalize the arguments and then proceed with the 
rest of the instructions.


-Chuck

_______________________________________________
Webware-discuss mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/webware-discuss

Reply via email to