Re: [Zope-dev] Designing ZPatterns/Python-product-based, reusable applications - take 2
Phillip J. Eby wrote:
At 10:24 AM 3/11/01 +1100, Itai Tavor wrote:
Then I need Specialists to manage collections of PD classes. I think that these would also benefit from being product-based, so I subclass Specialist to create a manager for each role in the application. Now, since an existing application might be expanded, the Specialists all need factory methods and will all show up in Zope's Add New Object menu.
Or you may want to just create one factory method that creates an entire family of related Specialists. Specialists do support TTW overriding of their methods, if you set up the methods properly in your Python code. (I forget how this works, though, you'll probably need to check the source code.)
The reason I think I need factory methods for all Specialists is that it would enable adding features to an existing site - so it would support multiphase development. About TTW overriding of Specialist methods - didn't even think to look for such an option. I'll check the code. It could be very useful.
- Many of the classes will also have web user UI, and since this has to be designed to fit the design of the web site in which the application is used, the UI methods will have to be located where designers can modify them - in the ZODB. For the Specialists, I can install a default set of UI methods when an instance of the Specialist is installed. But where do I store PD class UI methods? EMarket's solution is to store them in the Specialist, but this not only breaks O-O rules, it can also be very ugly. Say I have a Specialist managing 3 PD classes. Instead of an index_html method for each class, I'll need class1index_html, class2index_html, class3index_html in the Specialist. And each class would have to define:
def index_html(self, REQUEST, RESPONSE, **kw): return self.class1index_html(REQUEST, RESPONSE, kw)
This is unacceptably ugly. But the only other thing I can think of doing is creating a ZClass for each PD class and store the UI methods there. But that's also pretty unacceptable. Is there a better solution?
Yes. Use "class_default_for_X" methods. (e.g. "def class_default_for_index_html"). This will make them capable of being overridden with a Class Extender in the Rack or Specialist.
Class Extenders! Wow! I mean, Wow! I mean, this is great! Let me catch my breath... I got to learn to look under my nose more often. I just assumed that everything in the DataPlugins Add menu (other than Link to Parent Plugin) was made redundant by the use of SkinScripts. Just got to figure out the best way to use them... with class_default_for_X there won't be any ZODB-accessible default code to develop on, so for UI methods, creating the Class Extender along with the Rack, and filling it with default DTML methods might be a better idea.
Next, I need object connections - these are created using SkinScripts. And as far as I can tell, I can't manage SkinScript in the product - they have to be in the ZODB. Which is ok in O-O land as they're not strictly part of the PD classes, but this means that PD classes don't actually work at all until someone comes and fills in the SkinScripts - so the class actually misses a lot of the code it requires to function. Also, it means SkinScript code can't be reused
with the rest of the application's components (except by cutting and pasting code pieces from an existing application).
Your factory code can set this up, although I admit it's ugly.
But when I run the factory code the SkinScripts don't exist yet... I create my DataSkins and install my Specialists and Racks first, then develop the SkinScript required by them... so the Python product never contains all the application code... unless I copy the SkinScripts back into the product. The problem here is that I don't write a general-purpose app that will later be customized into a working project - I write a custom app for a specific project, which I will later want to reuse. So when I finish development of the first app, parts of it are in the ZODB. At this point, copying them back into the product makes sense for the purpose of instantiating new copies of the product, but not for that app itself, because maintenance/bug fixes will still be done on the ZODB copies.
Finally, I need to wrap the whole thing up as an application. So I create a Folderish class which installs instances of all Specialists, and add application-wide utility methods. Or do I simply place all Specialists in a Folder?
Placing them in a folder would be fine. Actually, it would suffice simply to install a meta type which creates all the Specialists in the selected folder. Note that Zope does not require that a meta type correspond to some physical class, or that an add operation result in a single object being added to a container; you can add as many objects as you want in the same operation.
Never thought about doing things that way... interesting.
Now, about reuse. O-O reuse, as far as I understand it, takes place at the class level. So how do I start a new application? Do I subclass its main container class and and my own init method that adds any added or subclassed Specialists I use? Or do I create my own application class and import PD classes from the old application? Do I copy the old classes into my new product, or do I import them from the old product, which then would require that the old product is kept on the server, even if the application that product defines isn't used on this server?
If I understand you correctly, then you'd just instantiate another instance of the application metatype, and then customize whatever needed to be customized.
I want every application I build to be based on its own object model. I can't stick to that if I instantiate an existing application, because that would bring in the entire object model of that application. I need to put together a collection of classes according to the object model, and some (often most) of these classes can come from the existing application. So my main problem here is how to get at these classes. Keeping a copy of the existing app to import classes from doesn't seem like a good idea... maybe I should get individual classes out of the CVS of the original application into the new product? But then what's to stop a programmer from going into these classes and changing them directly instead of subclassing them?
And, as mentioned above, how do I reuse SkinScripts, Rack methods and SQL methods? Copy and paste? It seems funny that if I create a new instance of the product, I don't get a new copy of a working application...
If your factory methods set this stuff up, then you're okay.
So after you finished developing the ZODB-based parts of an application, you copy them into the product so it can install them the next time it's instantiated?
On the other hand, considering that ZPatterns is now being superceded before it even had a chance to mature, maybe nobody cares to hear about it anymore :-( But more on that in a separate post.
IMHO, ZPatterns is actually pretty mature - in terms of its code. By that I mean, it has gone about as far in capabilities as its internal architecture will allow. There are many minor improvements that could be made, but they would be costly compared to their benefit. I would rather invest the effort in something that will produce a greater gain for me and the rest of the community. TransWarp will be much better for filesystem-based, Python products than ZPatterns, which is almost 100% through-the-web focused.
Would you say then that it would be a better idea to keep ZPatterns development in the ZODB? Or is it worth the extra trouble to use Python products, even if ZPatterns is not designed to make that particularly easy?
he key phrase, though, is "will be". Right now, ZPatterns is the premier system for doing "virtual objects" in Zope, and will continue to be for some time. If Ty or I had to start on a new app today that needed the things ZPatterns does, we would definitely use it. But we would also probably take the time to prepare a good UML model for the app, so that we could more easily port to TransWarp when it gets closer to being finished.
This brings up another thing that bothers me: When I started learning object models and ZPatterns everyone advocated using Coad notation. Now Peter Coad himself is using UML and you're building TransWarp around UML. Is this a conspiracy to confuse me? Itai -- -- Itai Tavor -- "Je sautille, donc je suis." -- itai@optusnet.com.au -- - Kermit the Frog -- -- -- -- "If you haven't got your health, you haven't got anything" --
Itai Tavor wrote:
This brings up another thing that bothers me: When I started learning object models and ZPatterns everyone advocated using Coad notation. Now Peter Coad himself is using UML and you're building TransWarp around UML. Is this a conspiracy to confuse me?
ZPatterns is very much about objects and collaborations between objects. The Coad notation is very good for talking about objects like this. TransWarp is more about classes, and generating customized classes from a mixture of existing classes and aspects. You can understand aspects as declarations about how to handle certain kinds of behaviour. UML is very good for talking about classes and the relationships that can exist between objects of particular classes. Often, I tend to think in Coad, but write in UML. -- Steve Alexander Software Engineer Cat-Box limited
participants (2)
-
Itai Tavor -
Steve Alexander