Date And Value Object

From FunctionObject...

This is an extremely valuable object we found working on LifeTech. It is so simple, but it makes solving so many problems trivial.

A Function is a function of value over time. The instance signature is:

+ , - aFunction => aFunction
/ , * aNumber => aFunction
valueOn: aDate => aNumber
integrate => aFunction
discountBy: , compoundBy: aNumber => aFunction (returns the integral of the NPV (or FV) of the receiver)

The constructors are:
on: aDate pay: aNumber
in: aPeriod pay: aNumber
in: aPeriod pay: aNumber every: aPeriodicity

With this and nothing more you can build models of interesting financial instruments like life insurance. In particular, where models like AccountsAndTransactions? are good at modeling a fairly certain past, Functions are good at modeling an uncertain future.

You could substitute a MoneyObject for numbers in the above and gain the ability to model multi-currency instruments.

Implementation Hints

Don't go crazy trying to duplicate Mathematica. Only implement the operations you need to model your situation. We found that we could get away with a much-less-than-complete-or-orthogonal implementation and still model everything we needed to model.

The classes in our system are:

Siggggghhhhhh. I hate to sound mainstream like this, but would someone be willing to give me a c++-esque version of this one?

MichaelFeathers went crazy trying to implement MoneyObject in C++. The structure of the two is very similar in some ways.

Discussion of ValueObjects (like MoneyObject) being AlgorithmsThatDemandGarbageCollection moved to ValueObjectsRequireGarbageCollection.

Sounds like you're creating class(es) that combine dates with monetary amounts. I'd probably have common interfaces, and multiple implementation classes, as the number and types of valid attributes vary with usage, and yet are fixed at construction time. Use a ClassFactory object (...which is what a SmalltalkLanguage class object is) if you like the simple creation syntax.

So, looking at the different uses (which I would make classes):

The common interface could include functions such as...

EditText of this page (last edited December 18, 2004) or FindPage with title or text search