[Tutor] OO approach

Prahlad Vaidyanathan slime@vsnl.net
Sun, 24 Feb 2002 22:59:55 +0530


I recently wrote a script to extract the urls in the news emails sent by
'The Register', and mail them to me. Initially, I just had functions to
do the following :

- read the file, and extract the urls matching a regex
- get the urls
- mail the urls to me with the description in the subject line

But, I soon realised I could do this to extract the URLs from the 'Linux
Journal' weekly announcements as well. So I made a class called
'mailURL', and added sub-classes for 'Register' and 'LJNews'.

I have now extended this script to include the 'Linux Weekly News',
'Kernel Traffic', and the 'LDP' news urls. What I noticed was, everytime
I added a sub-class, I would notice something missing or something
specific to 'Register' lying the the base 'mailURL' class.

So I ended up going back and re-writing the mailURL class over and over
again, everytime I added a sub-class. This defeats the purpose of using
inheritance (I could simply write 10 different classes completely
unrelated). So, what I want to ask you all is :

- How do I make a minimalistic base class (not just in this situation,
  but any task), and yet make it useful enough for the sub-classes.

I am trying to learn programming, and have started learning python as it
is very readable compared to the other languages, and also high-level. I
am enjoying it, but am having trouble grasping these fundamental
concepts of the object-oriented approach. I hope you can help out (and I
hope I've been clear enough).

Prahlad Vaidyanathan  <http://www.symonds.net/~prahladv/>

No amount of genius can overcome a preoccupation with detail.