[Tutor] OOA and OOD resources?

Magnus Lyckå magnus@thinkware.se
Tue May 20 16:50:03 2003


At 21:25 2003-05-19 -0700, Scott Chapman wrote:
>I'm learning python and oo at the same time. I'm currently looking for more
>grounding in practical ooa and ood.  The basic question is "How do I know
>what to make objects out of and what are the pitfalls of doing it this way
>vs. that way?"
>
>I have read various chunks here and there, saying things like, 
>"Inheritance is
>not good because it creates dependencies", or "Aggregation is good but it's a
>pain to implement the proxy methods".

Inheritance means IS-A, such as "employee IS A person", and aggregation
means HAS-A, like "a car HAS A motor". You don't use either or. You use
what is appropriate in a particular case.

The problem with inheritance occurs when it's used out of it's proper
place. It sometimes seems convenient to make a car object behave as a motor
object, but it's not really a good idea in the long run... Inheritance
should only be used to model a specialization hierarchy. A Car is not
a special kind of Motor. A Car is a special kind of Vehicle. This doesn't
mean that whoever makes a Car class should inherit from a Vehicle class.
But by using inheritance well, you will notice that you will remove a
lot of duplication of code.

If you have the same code duplicated in two classes, it's possible that
one should inherit the other, or that both should inherit a common base
class. But only if the general rules above apply... Maybe the right thing
is to put the shared code in a third classes that the two classes that
previously contained the code just uses or has as an aggregate.

>Are there any textbooks out there that start with oo (even ooa and ood) and
>build from there?  I see that introductory books deal with the language
>elements and a basically procedural orientation, then add oo later as
>"advanced".  I'd love to see a textbook that starts on oo and builds on it.

There are two books I'd like to recommend on Object-Orientation.
Neither use Python, but they are certainly applicable for Python
programmers.

* Bertrand Meyer: Object-Oriented Software Construction

* Arthur Riel: Object-Oriented Design Heuristics

Meyer is somewhat of a fanatic :) and you should take his
writing with a pinch of salt. If you want someone who always
weighs his words, and presents different alternatives, you
won't like Meyer. He strongly believes in his tenets. The
book contains a certain amount of propaganda for his own
language "Eiffel". It's a thick book. About 1250 bible thin
pages.

Riel seems more reasonable, and his book less than 400 pages.
I think it's the best description on how to design classes
that I've seen. Natuarally, there are things one can question
here as well, but he has a lot of good ideas, a if you read
through this book, I hope that you will get a feeling for how
to distribute the data structures and logic you need into a set
of useful classes.

Of course, nothing will ever replace real world experience...

>I'm fairly sure that no such book exists for Python but I'd love to be proven
>wrong!

I think you are right. :( The concept of creating objects is
enough for several book. Teaching an obscure ;) language
at the same time is maybe not the best idea (unless it's
the author's pet language, as Eiffel for Meyer :).

The concept of OO is fairly orthogonal to the programming
language Python. I do think that Python would be a fairly
good language to use to explain OO in, although there are
a lot of limitations in most other OO languages that Python
doesn't have, such as polymorphism limited by inheritance,
so other languages are likely to be frustrating to people
who learnt OO through Python...



--
Magnus Lycka (It's really Lyckå), magnus@thinkware.se
Thinkware AB, Sweden, www.thinkware.se
I code Python ~ The shortest path from thought to working program