[Tutor] Follow up to 'class data'

Andrei Kulakov ak@silmarill.org
Tue, 04 Dec 2001 06:13:38 -0500

On Tue, Dec 04, 2001 at 10:55:03AM -0000, alan.gauld@bt.com wrote:
> > Well, classes "hide" data so that it's harder to mess it up 
> > The fancy name for this is data incapsulation, I think. 
> Actually its 'data hiding'. 
> Encapsulation is the process of combining data and function into
> a single blob - an object. There are many OO languages which 
> implement encapsulation without data hiding - early Python 
> being one!(and still does by default).
> Unfortunately even many modern books have gotten these 
> terms mixed up which is an unfortunate side effect of 
> the industry's confusion between OOP and C++!
> > Now OO gurus will have a heart attack because I like classes 
> > for all the wrong reasons ;-P.
> Sounds like exactly the right reasons to me!
> Of course those advantages pave the way for other exciting
> features like asbstract classes etc too, but they are a 
> consequence of the fundamental features you describe.

I mentioned data hiding because I've heard about it, but I didn't find it
helpful myself (yet). I guess the things I described - easier way to
change data without globals or passing arguments back and forth - can be
filed under data encapsulation? Umm.. now that I thought about it for a
bit, I guess I only use one of classes "niceties":

1. Encapsulation - makes it easier to make a mental picture of your
program, you can create objects and associate both actions and data with
it. Otherwise you'd have them all over the place and that's confusing.
That's all I'm using classes for.

2. Polymorphism - I totally have no idea what does it mean in practice.
I read in some java book that it allows you to handle different types of
data easily, or somesuch.

3. Data hiding - I guess it's useful in very large projects where many
people are working on the code and you want to protect your data from
the silly intern in the next cubicle?

4. Inheritance - I used it a little bit but I could do without it just
as well. It pretty much saves typing and maintainance time, right?

> Alan G

Cymbaline: intelligent learning mp3 player - python, linux, console.
get it at: cy.silmarill.org