Books about refactoring in Python (Was: A design problem I met again and again.)

Michele Simionato michele.simionato at
Sat Apr 4 07:21:07 CEST 2009

On Apr 4, 6:10 am, Carl Banks <pavlovevide... at> wrote:
> A piece of user code that looked like this (where sc is an instance of
> your enormous class):
> sc.startX()
> sc.send_data_via_X()
> sc.receive_data_via_X()
> sc.stopX()
> might look like this after you factor it out:
> session = sc.startX()  # creates and returns a new XSession object
> session.send_data()    # these are methods of the XSession
> session.receive_data()
> session.stop()
> Any methods that are callable any time, you can retain in the big
> class, or put in a base class of all the sessions.

That's good advice. A typical refactoring technique when
working with blob classes is to extract groups of methods
with commmon functionality, put them in a helper
class, make a helper object and pass it to the
original blob. In other words, tp split the blob
object as a composition of small logically independent
objects. BTW, is there anybody in this lists that
can suggest good books about refactoring in Python?
There are plenty of books about refactoring for Java
and C++ but on top of my mind I cannot think of a Python
book right now.

More information about the Python-list mailing list