views:

34

answers:

1

Hello,

We have an object that can has an effective date and expiry date.(Ex. i want to maintain the price of a commodity for a time period)

Business Rules -
Effective date is always a valid date (a datestamp) but, expiry date can be null to indicate that the object is active throughout. Also, both effective and expiry date can be set to some valid dates.

Are there any frameworks that manage objects such that the objects are consistent,i.e there are no overlaps of the validity periods ?

Ex.

class XBOX{
 double price;
    Date effectiveDate;
    Date expiryDate;
 }

XBOX x1 = new XBOX(400$, '2007-01-01','2008-12-31' );
XBOX x2 = new XBOX(200$, '2009-01-01',null );

Assume that we get a new rate from '2010-01-01' and a new XBOX object has to be created (to persist).

Is there a framework/pattern that can do the following, so that the XBOX is consistent.

  1. x2.setExpiryDate('2009-12-31')
  2. XBOX x3 = new XBOX(150$, '2010-01-01',null );

Thanks in advance.

A: 

I don't know of any framework that will handle this for you. If you build it yourself, I suggest you just store a list of prices and start dates for each product. So, for your example above, I'd store:

price start_date
400   2007-01-01
200   2009-01,01

Then you won't have to worry about overlapping or underlapping datespans since the data structure wouldn't support it.

Jeremy Stein