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...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

DelegationA Composed Method needs work done by another object. A Message invoked computation inanother object.How do you share implementation without inheritance?Inheritance is the primary built-in mechanism for sharing implementation in <strong>Smalltalk</strong>. However,inheritance in <strong>Smalltalk</strong> is limited to a single superclass. What if you want to implement a newobject like A but also like B? Also, inheritance carries with it potentially staggering long-termcosts. Code in subclasses isn’t just written in <strong>Smalltalk</strong>, it is written in the context of every variableand method in every superclass. In deep, rich hierarchies, you may have to read and understandmany superclasses before you can understand even the simplest method in a subclass.Factored Superclass explains how to make effective use of inheritance at minimal developmentcost. You will encounter situations where you will recognize common implementation, but whereFactored Superclass is not appropriate. How can you respond?Pass part of your work on to another object. Other objects can also delegate to that object (oranother instance of the same class).Use Simple Delegation when the delegate need know nothing about the original object. Use SelfDelegation when the identity of the original object or some of its state is needed by the delegate.<strong>Coding</strong> <strong>Patterns</strong> page 50 of 147 9/30/2006

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

Saved successfully!

Ooh no, something went wrong!