13.07.2015 Views

Smalltalk Best Practice Patterns Volume 1: Coding - Free

Smalltalk Best Practice Patterns Volume 1: Coding - Free

Smalltalk Best Practice Patterns Volume 1: Coding - Free

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Converter Creation MethodYou need to implement Conversion to a new kind of object.How do you represent the conversion of an object to another with different protocol?In many ways, the simplest way to communicate the presence of a conversion is a ConverterMethod. If I am explaining Date to you and you already know about Strings, it is tempting to say,“You can just convert a String to a Date by sending asDate to the String.”This solution risks cluttering common sources of conversion like Strings and Numbers withprotocol that is irrelevant to their primary mission. The Visual <strong>Smalltalk</strong> implementation of Stringhas 36 as... methods, half of which return objects with completely different protocols. I have seenapplications where String has more than 100 of these methods.Make a Complete Creation Method that takes the object(s) to be converted as arguments.For example, Date class>>fromString: is a Converter Creation Method. It takes the String to beconverted as an argument and returns a Date.You need to choose an Intention Revealing Selector for the method.<strong>Coding</strong> <strong>Patterns</strong> page 30 of 147 9/30/2006

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!