Re: [Tutor] Question about Classes
Magnus Lycka
magnus at thinkware.se
Tue Nov 25 16:11:26 EST 2003
> So if the goal is to maximize code reuse, would the correct solution require that
> the Emails class be placed in another module that can then be imported whenever the
> Emails functionality is required or is there a better way to do this?
It's ALWAYS a goal to keep things simple. If the class
is as simple that Email class, it's hardly worth a lot
of administrative efforts making it a deliverable in
itself that needs to be maintained.
In contrast to Java, it's not a typical Python idiom to
place each class in its own module. Since Python is a
higher level language than Java, Python modules with only
one class would tend to be rather small. It's normal to
place related classes together in a module.
On one hand, it's always good to do things right at once,
but on the other hand, what's right in one situation is
wrong in another, and things change over time. Trying to
solve thing in a "good for the future" way often means that
you spend time and energy making your system more complicated
for no good reason.
Finding the right balance between planning ahead and staying
simple and flexible is something you will have to learn over
time.
A great thing with Python is that it's so flexible. I'd put
the Email(s) class with the Contact class in a shared module.
You can import that in some other program and just use the
Email class. If it grows, and you feel it should have a module
on it's own, it's time to refactor your code and break it out.
--
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/ mailto:magnus at thinkware.se
More information about the Tutor
mailing list