![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
Chapter 27: | How To Define Binary Methods |
In this segment, you learn how to define binary methods and you learn how to define your own numberlike classes.
In particular, you learn how to define a Weight
class, so that you
represent weight quantities explicitly, using Weight
instances,
rather than implicitly, using instances of one of the number classes. The
Weight
class has some numberlike properties, such as answering to
magnitude-comparison, addition, and subtraction methods, buts lack others,
such as answering to exponentiation methods. Thus, the Weight
class
is reminiscent of the built-in Time
and Date
classes, which
you learned about in Chapter 26.