A design problem I met again and again.

Nick Craig-Wood nick at craig-wood.com
Wed Apr 1 14:30:05 EDT 2009


一首诗 <newptcai at gmail.com> wrote:
>  But I think the first step to resolve a problem is to describe it.  In
>  that way, I might find the answer myself

:-) That is a great saying!

To answer your original question, split your code up into sections
that can be tested independently.  If you can test code in a isolated
way then it belongs in a class / module of its own.

If you have a class that is too big, then factor independent classes
out of it until it is the right size.  That is easier said than done
and may require some creativity on your part.  It will pay dividends
though as the level of abstraction in your program will rise.

I've noticed some programmers think in big classes and some think in
small classes.  Train yourself to do the other thing and your
programming will improve greatly!

-- 
Nick Craig-Wood <nick at craig-wood.com> -- http://www.craig-wood.com/nick



More information about the Python-list mailing list