[Tutor] Understanding the OOP Worldview

Alan Colburn aicolburn@yahoo.com
Mon, 12 Aug 2002 12:42:52 -0700 (PDT)


I recently posted a question about assigning keys for
entries saved in a dictionary/database. I was writing
a program for creating a log to save information about
students visiting me for advising (in my post I used
the example of patients visiting a medical office;
same idea). Multiple people responded and, first, I'd
like to thank you all!

Probably 3 of 5 responses noted that this was
something that might be better if written with
objects. That's where my question today comes in ...
Why might an OOP approach be better here? 

With the program as is, users can do things like 
* make a new entry (i.e., add information about a
student who just visited you, their advisor, noting
the student's name, date, and other info. Each entry
is grouped into a list, which becomes a dictionary
value.), 
* count the total number of visits (len(dict)), 
* get a list of all the entries (sorted by last name,
with name and date printed), and 
* query the database (you can use first or last name)
to see whether you've met the student before. If
there's a name match, the whole record is printed out.

I've also got a couple small functions, one to
translate mmddyy date info into mmm dd yyyy format,
and another to print an entry (translating list
members into pretty output). 

In other words, it's pretty basic.

With my limited knowledge of OOP, it seems like I'd
end up with pretty much the same number of lines of
code either way, and the same effort required on my
part, if I wrote this program via OOP. Statements
governing the stuff I put next to asterisks above
would be encapsulated into functions, which in turn
become part of a Class statement. It would be the same
statements I wrote, though--just rearranged and
ultimately accessed via fancy dot notation :-)

I am sure there are advantages, even here, to having a
class for database entries, and advising session
'objects.' ... I just don't know what the advantages
are. Thoughts?

Thanks, as always -- Al


__________________________________________________
Do You Yahoo!?
HotJobs - Search Thousands of New Jobs
http://www.hotjobs.com