Home Segments Index Top Previous Next

556: Mainline

Now you are ready to bring together all the fragments for testing:

Weight class definition 
Magnitude subclass: #Weight 
  instanceVariableNames: 'magnitude' 
  classVariableNames: '' 
  poolDictionaries: '' 
Weight method definition • instance 
magnitude 
  ^ magnitude 
Number method definition • instance 
gm 
  ^ Weight new initialize: self 
Weight method definition • instance 
initialize: aNumber 
  magnitude := aNumber 
Weight method definition • instance 
printOn: aStream 
  aStream nextPutAll: magnitude asString , 'gm' 
Weight method definition • instance 
+ aWeight 
  ^ (self magnitude + aWeight magnitude) gm 
Weight method definition • instance 
< aWeight 
  ^ (self magnitude < aWeight magnitude) 
Workspace
Transcript show: 3gm printString; cr; 
           show: (3gm + 2gm) printString; cr; 
           show: (3gm < 2gm) printString; cr 
Transcript 
3gm 
5gm 
false