User Tools

Site Tools


at-m42:lecture7

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
at-m42:lecture7 [2009/04/13 15:53] eechrisat-m42:lecture7 [2011/01/14 12:45] (current) – external edit 127.0.0.1
Line 749: Line 749:
 } }
  
-abstract class AbstractItem implements Portable { ...  }+abstract class AbstractItem implements Portable { ... }
  
 class WeightyItem extends AbstractItem { ... } class WeightyItem extends AbstractItem { ... }
-} 
  
 class MagicalItem extends AbstractItem { ... } class MagicalItem extends AbstractItem { ... }
 </code> </code>
 +
 +Full listing for [[http://www.cpjobling.org.uk/~eechris/at-m42/Examples/lecture07/example15.groovy|Example 15]] is given in the notes.
 +
 +----
 +
 +The implementation for this is give in Example 15, where ''Portable'' is introduced as a an interface class. An interface declares, but does not define, one or more abstract methods. The abstract class ''AbstractItem'' conforms to the protocol since it //implements// the ''Portable// interface. Notice that ''AbstractItem'' offers a simple implementation for the ''canCarry'' method. We must explicitly redefine it in the ''WeightyItem'' and ''MigicalItem'' classes (note we use the superclass definitions in both!).
  
 <code groovy 1 | Example 15: The interface calls (at-m42/Examples/lecture07/example15.groovy)> <code groovy 1 | Example 15: The interface calls (at-m42/Examples/lecture07/example15.groovy)>
at-m42/lecture7.1239638029.txt.gz · Last modified: 2011/01/14 12:25 (external edit)