Newbee interfaces and implementations
Hello, I'm in the process of learning to develop fs-zope-products. The developers guide recommends to write interfaces and implement them in classes. Now my question: When I have an interface: DoThings with several methods: doThis() doThat() doThattoo() ... and I have an implementation: DoThingsClass How will I then access the methods e.g. in a Template? Through the interface: tal:define="context/DoThings/doThis" or through the implemantation: tal:define="context/DoThingsClass/doThis" I would think the first one should be the case. But then how does the interface know where the implementation of the method is defined since it doesn't import the implementation? I'm currently on Zope 2.84. Please shed some light on me! Greetings Roman
Roman Klesel wrote:
Hello,
I'm in the process of learning to develop fs-zope-products.
The developers guide recommends to write interfaces and implement them in classes. Now my question:
When I have an interface:
DoThings
with several methods:
doThis() doThat() doThattoo() ...
and I have an implementation:
DoThingsClass
How will I then access the methods e.g. in a Template?
myObject = DoThingsClass(any_args_here) myObject.doThis()
Through the interface:
tal:define="context/DoThings/doThis"
should be: tal:define="some_name context/some_thing/some_attribute_or_method"
or through the implemantation:
tal:define="context/DoThingsClass/doThis"
Looks like you're newbie to OO too !-) A class defines a type. You then need to have an instance of that type (like, say, 42 is an instance of type integer and 'foo' is an instance of type string). (Interfaces (I mean, 'explicit' interfaces) defines an 'abstract' type, that can be implemented by many classes. With Python's dynamic typing, you don't *need* explicit interfaces - at least with Zope 2.x. AFAICT, the recommandation to use explicit interfaces is mostly about Zope3 relying on them to implement some nice features). So it would be: tal:define="some_name context/myObject/doThis" As you see, you don't have to worry about interface at this level...
I would think the first one should be the case.
And you would be wrong.
Please shed some light on me!
Hope that does... -- bruno desthuilliers développeur bruno@modulix.org http://www.modulix.com
bruno desthuilliers schrieb:
Looks like you're newbie to OO too !-)
A class defines a type. You then need to have an instance of that type (like, say, 42 is an instance of type integer and 'foo' is an instance of type string).
Yes, true! :-)
(Interfaces (I mean, 'explicit' interfaces) defines an 'abstract' type, that can be implemented by many classes. With Python's dynamic typing, you don't *need* explicit interfaces - at least with Zope 2.x. AFAICT, the recommandation to use explicit interfaces is mostly about Zope3 relying on them to implement some nice features).
So it would be:
tal:define="some_name context/myObject/doThis"
As you see, you don't have to worry about interface at this level...
So you recommend that I should just skip them as long as I'm on Zope2? I would be happy with that. I find them confusing when they don't really interface with but just document my methods. Thanks Roman
So you recommend that I should just skip them as long as I'm on Zope2?
I would be happy with that. I find them confusing when they don't really interface with but just document my methods.
Some of the reasons interfaces can be helpful are (1) for documentation purposes and clarity for code if someone needs to look at it, (2) if other classes might use the same interface, you help make sure you're sticking to a common interface so that the methods in different classes do similar things, and (3) you can use methods like "isImplementedBy" so that certain templates, code, etc. does something with an object or class if it uses the interface -- what you call "really interfacing". There's many examples of how (3) might work. It seems like for now that (3) won't be important to you and (2) might be. Personally I define interfaces for some classes (especially tools) to help with the documentation, but agree with you that for other straightforward classes they don't help that much with documetnation. Hope this helps; peace, George
Roman Klesel a écrit :
bruno desthuilliers schrieb:
Looks like you're newbie to OO too !-)
A class defines a type. You then need to have an instance of that type (like, say, 42 is an instance of type integer and 'foo' is an instance of type string).
Yes, true! :-)
!-)
(Interfaces (I mean, 'explicit' interfaces) defines an 'abstract' type,
that can be implemented by many classes. With Python's dynamic typing, you don't *need* explicit interfaces - at least with Zope 2.x. AFAICT, the recommandation to use explicit interfaces is mostly about Zope3 relying on them to implement some nice features).
So it would be:
tal:define="some_name context/myObject/doThis"
As you see, you don't have to worry about interface at this level...
So you recommend that I should just skip them as long as I'm on Zope2?
Short answer : yes. Unless you plan to switch to Zope3 really soon, but then, I'd recommand that you skip Zope 2.x !-)
I would be happy with that. I find them confusing when they don't really interface with but just document my methods.
The Interface package offers much more than simple documentation. But I don't think you will find much Zope 2.x code using it. My 2 cents
bruno modulix schrieb:
So you recommend that I should just skip them as long as I'm on Zope2?
Short answer : yes. Unless you plan to switch to Zope3 really soon, but then, I'd recommand that you skip Zope 2.x !-)
No, I'll be with Zope2 for a while. I'm running an Plone site too and dont't have the memory to run a second Zope3 instance. I think my question is answered and I'm a little less confused now. :-) When I heard the word "interface" I thought of something like a network interface, which is the communication gateway to the entire machine if you address it from network: - you physically connect it to the network by plugging a cable into the NIC - you address it by calling an address which is assigned to the NIC. actually all other devices on the network only see the target machine as a network interface and don't know what kind of system it is plugged into until the methods the interface provides trigger routines that reveal more information. So, now I understand that interfaces in a the Zope2 context have some different meaning. Maybe I should understand them as "pseudo interfaces". Roman
Roman Klesel wrote:
bruno modulix schrieb:
So you recommend that I should just skip them as long as I'm on Zope2?
Short answer : yes. Unless you plan to switch to Zope3 really soon, but then, I'd recommand that you skip Zope 2.x !-)
No, I'll be with Zope2 for a while. I'm running an Plone site too and dont't have the memory to run a second Zope3 instance.
I think my question is answered and I'm a little less confused now. :-)
When I heard the word "interface" I thought of something like a network interface, which is the communication gateway to the entire machine if you address it from network:
- you physically connect it to the network by plugging a cable into the NIC - you address it by calling an address which is assigned to the NIC.
actually all other devices on the network only see the target machine as a network interface and don't know what kind of system it is plugged into until the methods the interface provides trigger routines that reveal more information.
So, now I understand that interfaces in a the Zope2 context have some different meaning.
It a programming context, really. You should think of programmatic interfaces like the interface between a power supply and a power consumer: as long as both agree that the plug should have an end like such, and the socket should look so and so, and the voltage is this, it doesn't really matter what's generating the power, what's consuming the power, or how the plug or socket is made. --jcc -- "Building Websites with Plone" http://plonebook.packtpub.com/ Enfold Systems, LLC http://www.enfoldsystems.com
Hi, I'm recoding an existing php e-commerce app in zope as my first project I'm at the point where I've installed the exUserFolder product to authenticate against an external SQL database. However, I need to hold some additional information in the user object. It seems to me that I have to change the exUserFolder product code to add this to the class. This seems odd and not very maintainable. There are brains for sql, I'm wondering if there are better ways for doing this? Any advice gratefully received. --john
Sorry should have added its zope 2.8 under windows --john John Huttley wrote:
Hi, I'm recoding an existing php e-commerce app in zope as my first project
I'm at the point where I've installed the exUserFolder product to authenticate against an external SQL database.
However, I need to hold some additional information in the user object.
It seems to me that I have to change the exUserFolder product code to add this to the class.
This seems odd and not very maintainable.
There are brains for sql, I'm wondering if there are better ways for doing this?
Any advice gratefully received.
--john
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
On 1/20/06, John Huttley <John@mib-infotech.co.nz> wrote:
Sorry should have added its zope 2.8 under windows
--john
John Huttley wrote:
Hi, I'm recoding an existing php e-commerce app in zope as my first project
I'm at the point where I've installed the exUserFolder product to authenticate against an external SQL database.
However, I need to hold some additional information in the user object.
It seems to me that I have to change the exUserFolder product code to add this to the class.
check out authentication source. also, check out all the docs in the xuf ta ball. iirc, there's a faq for this.. hth
This seems odd and not very maintainable.
There are brains for sql, I'm wondering if there are better ways for doing this?
Any advice gratefully received.
--john
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- http://myzope.kedai.com.my - my-zope org
Bakhtiar A Hamid wrote:
On 1/20/06, *John Huttley* <John@mib-infotech.co.nz <mailto:John@mib-infotech.co.nz>> wrote:
Sorry should have added its zope 2.8 under windows
--john
John Huttley wrote: > Hi, I'm recoding an existing php e-commerce app in zope as my first > project > > I'm at the point where I've installed the exUserFolder product to > authenticate against an external SQL database. > > However, I need to hold some additional information in the user object. > > It seems to me that I have to change the exUserFolder product code to > add this to the class. >
check out authentication source. also, check out all the docs in the xuf ta ball. iirc, there's a faq for this..
hth
> This seems odd and not very maintainable. > > There are brains for sql, I'm wondering if there are better ways for > doing this? > > Any advice gratefully received. > > --john >
I use SimpleUserfolder to authenticatate against postgres. Its easy to add addional user information. Heres a short version of how this similar product works: a) you store authentication data in an SQL table (or anywhere thats persistent). b) you write a handful of scripts to satisfy Zope's authentication machinary (examples are provided). c) you can obtain additional user information by calling your SQL tables with userID, eg obtain their phone, fax and socials - or right after authentication you can stuff the users details into SESSION. David David
+-------[ John Huttley ]---------------------- | | Hi, I'm recoding an existing php e-commerce app in zope as my first | project | | I'm at the point where I've installed the exUserFolder product to | authenticate against an external SQL database. | | However, I need to hold some additional information in the user object. | | It seems to me that I have to change the exUserFolder product code to | add this to the class. All you need to do is configure a property source. You can store properties in the ZODB or in SQL, or pretty much anywhere. -- Andrew Milton akm@theinternet.com.au
Thanks for your help on this. I'll study it up shortly. Regards, John
participants (9)
-
Andrew Milton -
Bakhtiar A Hamid -
bruno desthuilliers -
bruno modulix -
David -
George Lee -
J Cameron Cooper -
John Huttley -
Roman Klesel