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.

Default Value MethodYou have a complicated default value in Explicit Initialization. You need a default value for LazyInitialization.How do you represent the default value of a variable?The simplest way to provide default values is right in line with the code. It’s generally easy to readand quick and simple to write.<strong>Patterns</strong> whose purpose is creating flexibility (Lazy Initialization), or who may need additionalcommunication (Explicit Initialization), need an Intention Revealing Message. It gives you anopportunity to communicate through the selector. It gives future subclasses the option of simplyoverriding a single value.Create a method that returns the value. Prepend “default” to the name of the variable as thename of the method.If you are computing the value of a Caching Instance Variable, call the method “computeArea”rather than “defaultArea”. This will provide a clue to readers that the variable is intended as acache.Use a Constant Method for constant default values.<strong>Coding</strong> <strong>Patterns</strong> page 66 of 147 9/30/2006

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

Saved successfully!

Ooh no, something went wrong!