![]() |
![]() |
![]() |
![]() |
![]() |
|
To construct new instances, you depart from
normal practice by sending a gm message to an instance of the
Number class, instead of sending a new message to the
Weight class. The number, which may be an Integer,
Float, or Fraction instance, then sends a new message
to the Weight class, which produces and initializes an instance:
Number method definition instance gm ^ Weight new initialize: self Weight method definition instance initialize: aNumber magnitude := aNumber
Using gm, you create new instances with expressions that look like
denominate numbers. For example, 3gm is actually an expression that
creates a new instance of the Weight class with 3 as the value of
the magnitude instance variable.