O'Reilly logo

Object-Oriented Computation in C++ and Java: A Practical Guide to Design Patterns for Object-Oriented Computing by Conrad Weisert

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required