5. The Point-Extent Pattern for Pairs of Numeric Types

5.1. Non-additive numeric types

5.1.1. Our first non-additive type: Date

Second only to amounts of money, dates are the most common data in commercial applications. Therefore, for business software, as well as many other applications, we certainly need a Date class.

As soon as we start looking at binary arithmetic operators, we see that the additive pattern we exploited in the previous chapter is inapplicable.

Image

What is the sum of two dates? What do we get by adding July 4, 1776, to December 7, 1941? Obviously, that sum is nonsense, and we’ll want to make it illegal.

5.1.2. Need for a companion ...

Get Object-Oriented Computation in C++ and Java: A Practical Guide to Design Patterns for Object-Oriented Computing now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.