[Tutor] working with time spans ?

Magnus Lyckå magnus at thinkware.se
Sat Jun 5 07:35:07 EDT 2004

At 00:50 2004-06-05 +0200, Michele Alzetta wrote:
>Would it be a good idea to make TimeSpan inherit from time and
>change the mktime method for instance ?

No. Even if it was technically possible, you should think of
inheritance as "is-a". I.e. an employee is a person, a manager
is an employee. A time span is not a time, any more than a
department is a person. A time span is an interval between two
times, so the concept to use is composition, not inheritance.
That is "has a" (or "has two" in this case) rather than "is a".
That means that you use two times (start and stop) as attributes
in the TimeSpan class, just as you've shown.

Magnus Lycka (It's really Lyckå), magnus at thinkware.se
Thinkware AB, Sweden, www.thinkware.se
I code Python ~ The Agile Programming Language 

More information about the Tutor mailing list