[Tutor] Follow up to 'class data'
Mon, 03 Dec 2001 13:07:13 -0500
On Mon, Dec 03, 2001 at 12:44:59PM -0500, firstname.lastname@example.org wrote:
> I think I'm stuck in the "just don't get it" class (pun intentional).
> "Everything is an object" includes, I guess classes.
> So to me, the address book is an object and can be a class?
> But the example seems to ignore "address book" and describes the means of
> adding, modifying, deleting data as classes. ??
> I would have thought "address book" would be the class and the means of
> adding, modifying, deleting data would be "methods."
> Since the actual data (names, addresses, phone numbers, e-mail addresses,
> etc.) will need to be stored in dictionaries, lists, text files, etc.,
> what is the advantage of using classes as opposed to functions. Or are we
> just talking about 'another way to do it?'
Well, classes "hide" data so that it's harder to mess it up by mistake.
The fancy name for this is data incapsulation, I think. You could also
subclass address book. Read some thick book on OOP, if you really want
I also find that it makes for more readable code if you use classes. For
instance, in my pybook (e-books reader) app, I at first had a bunch of
global vars and functions, so local_books list, and read_last() method,
and so on.. now, I have books.local list, and books.read_last() method,
so I can think in terms of having this big blob "books" that I can apply
In addition, if you have some data you want to change in your function
and you aren't using classes, you'll either have to use it as global or
pass it in functions and return it back. Either option adds unnecessary
clutter to the program, and globals just feel wrong..
Now OO gurus will have a heart attack because I like classes for all the
wrong reasons ;-P.
> The structure as I see it would be something like:
> class AddressBook:
> def input:
> def modify:
> def delete:
> def search:
> def sort:
> def output:
> Should I be looking at something like:
> class AddressBook:
> class Input(AddressBook):
> def inputName:
> def inputAddress:
> def inputPhone:
> - fleet -
> Tutor maillist - Tutor@python.org
Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org