[Zope] Gaining Enlightenment
Richard Moon
richard@dcs.co.uk
Tue, 07 Mar 2000 09:47:21 +0000
Dear Zopers,
I read Chris McDonough's How To on Gaining Zope Enlightenment by Grokking
Object Orientation. It raised a few questions in my RDBMS-oriented head. So
I mailed Chris with these questions but Chris explained he just couldn't
answer them right now and asked me to post them to the list. They seem very
basic, very fundamental questions to me.
So here is my email to Chris - If I get any answers here I would like to
include my questions and your answers in a How-To to help those who come
after me !
Thanks for any help !
Here's the original email
----------------------------------------------------------------------------
----------------------------------------------------------
Chris,
I enjoyed your How-To on Gaining Enlightenment very much. I've been using
Zope for a couple of months now and I've made some progress - my first
project has been to use it to give access to established databases over an
Intranet. Like you I think its wonderful, but like you I keep getting
stuck. Never mind, with the help of the mailing lists and long hours
reading books on Python etc I've made progress.
BUT ... (there's always a but isn't there) - no matter how much I read and
play around with OO - I still don't 'get it'. My background is many years
working with relational databases on Unix - (and there are thousands like me).
I just don't get the bit about storing data as objects. Could we discuss
this a bit more and perhaps publish my questions and your answers on
Zope.org ?? This may help me and the thousands like me.
OK, you create your class of Spam, which has attributes of cansize and
texture and it has methods that display these attributes. No doubt you
could add other attributes, such as selling price and develop a method to
increase the price by a percentage. OK so far ?
Now we create an object (which is an instance of the class Spam) - which we
call myfirstcan. We can define the attributes for that object when we
create it or later and we can use the methods defined in the Spam class to
do so. OK so far ?
What I don't get is how you store and retrieve the objects you create.
Let's go to a more realworld example - how would you implement a stock
system using objects ? Let's take the simple table Stock which has three
columns
Product_code Description Price
and we could enter rows of data into it, for example -
ABC Spluggifier 20.00
CDE Super-spluggifier 25.00
Now if I was writing a conventional database system I would maintain the
above by defining a program which perhaps prompted the user for the
required columns (Product, Description,Price) and then I would store the
users input in a row in a table. Perhaps another program (the price change
program) would use a stored procedure to allow price change. OK ?
Now in OO terms I see that I could create a class of Stock with attributes
Product, Description and Price. I could create a method to allow price
changes. Very neat.
Then I can create an object( i.e a particular stock item) by saying
something like
product_1 = Stock(product_code="ABC", Description="Spluggifier", Price-"20.00")
Now I can create another object by saying
product_2 = etc
but that is not the way you would do it surely. You would be effectively
'hard-coding' each product in your system.
Surely you would have a program which did something like
WHILE the user is entering data
PROMPT user for data
VALIDATE data
WRITE data to database
END WHILE
How do you do that in OO terms ?
How then do you search and retrieve an object with a particular value of
product_code ?
How do you write a program which updates the price of all stock items where
the product_code begins with AB by 2%.?
Thanks for reading this far. Hope you can stop my head spinning !
Regards
Richard
Richard Moon
richard@dcs.co.uk