[Tutor] Program review

Kent Johnson kent37 at tds.net
Sat Jan 5 21:08:19 CET 2008


Ricardo Aráoz wrote:
> Ok, here is a corrected new version, I hope.
> 
> Kent, the fact that Mensaje.__init__ reads the message configuration is
> by design (it's a feature, not a bug ;c) ).

You misunderstood my suggestion. I would add a method to Mensaje that 
creates the email.MIMEMultipart.MIMEMultipart() currently done by 
Correo.__init__().

Almost every line of Correo.__init__() is reading data from attributes 
of mensaje. This is a code smell called Feature Envy and is a clear sign 
that the code is in the wrong place.

In Mensaje you could have
     def createMessage(self):
         messg = email.MIMEMultipart.MIMEMultipart()
         messg['From'] = self.De
         messg['To'] = self.Para
         messg['Subject'] = self.Encabezado
         messg['Reply-To'] = self.ResponderA
         messg.preamble = 'This is a multi-part message in MIME format'
         messg.attach(email.MIMEText.MIMEText(self.html, 'html'))

Then in Correo.__init__() you would have
         self.messg = mensaje.createMessage()

It doesn't change the functionality but it is a better design.

Kent


More information about the Tutor mailing list