Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

RE: Object Oriented SQL

by BastardOperator (Monk)
on Sep 10, 2000 at 03:45 UTC ( #31774=note: print w/replies, xml ) Need Help??


in reply to Object Oriented SQL

NOTE: please don't flame me for the following ;)

Too late, I'm getting down voted, aaahhh ;) oh well...

I recently wrote a web app in *duck* Python *peek**duck again*, in which I did exactly that, and it worked out quite nicely. I had a module for the sql, one for the html, a config module, a content module which was basically a Super class of a web page which was then subclassed for each page on the site. The url to get the code would be http://members.home.com/m.v.wilson.

The sql module probably could have been split up some, but due to Python's lack of anything close to mod_perl, I couldn't get persistent db connections, so the sql module's constructor created the database connection, the destructor broke it down. That way I only had one database connection per page. Each thing I wanted to do was represented by a method of that class (from that module). So, even down the road as I add pages, I can simply create a new method, and create the subclass with that method in it. Plus, I tried to keep a lot of the methods fairly generic so that I didn't _always_ have to create new ones.

I had actually written that app in Perl previously (should have stuck with it ;)), but everything was hardcoded, the html, sql, and everything else. It was quite ugly and every time I wanted to say...change the color of some part of the page, I had to edit 8 different cgi's. (that was my first perl project, so it wasn't too clean ;)).

Modularizing everything is great for say, producing apps which can have a console/gui/html interface, the logic is seperated out from everything else, so you just pull in what you need.

Another upside to the way that I wrote the python app is that I only had one cgi that was ever called. Even if someone could see the cgi source, they would never be able to get the database username and password, etc. 'cuz it was in a module outside of the chroot jail. That cgi was more or less just a traffic cop with a couple big if statements that created an instance of a class depending on what the specified "action" was.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://31774]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2022-05-24 03:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (82 votes). Check out past polls.

    Notices?