[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

The problem of History Objects



Hi,
Following is a description of a problem that I keep running into in my
project. I dont know if its a pattern or merely a design decision.
I'll let you decide and tell me!

In my project I often come accross a problem in which two classes, say,
Person and HomeAddress have a relationship. A person may change addresses
often, but at a time he may have only one HomeAddress. At the same
time, we want to store the past addresses for record's sake (or
sometimes it is legally required). What
is the cardinality of the relation? If we make it 1:m (Person has many
HomeAddresses), then we must have another business rule that says "A
person may not, at any time, have more than one current HomeAddress". But
this information is not obvious from the Object Diagram. If we make it 1:1
we have to instantiate a new Person for every new HomeAddress. The problem
here is that we want to store the past state of the object (or the past
object of the same type). And also we want to know the time period that 
the object was active during.How can we do this? There's one solution that
I can come up with right now. For the class HomeAddress, build another
class called HomeAddressTimer, that has as attribute, a pointer to object
of type HomeAddress, an attribute of type TimePeriod, and perhaps an
boolean attribute Valid.


__________                __________________         _______________
|        |          1...* |HomeAddressTimer |   1...1|             |
| Person |--------------- |                 |--------|HomeAddress  |
|        |                |                 |        |             |
----------                ------------------|        ---------------
                            |               |
                            |               |
                            |1...1          |1...1
                        ______________    _____________
                        |            |    |           |
                        | TimePeriod |    |    Valid  |
                        |            |    |           |
                        --------------    -------------

So  now, a person can have many HomeAddresses with their time periods and
also know which are valid (current) and which are not (past). WHat this
model does not take care of is the (possible) constraint that there be
only one current HomeAddress. (At one time a person may have only one
active HomeAddress). How do you ensure that?

Is there any other/better  way? Do excuse me if this has been
discussed/documented. In case of the latter, please  point me to it!

Jinny.

Life is what happens when you are busy elsewhere. -John Lennon (Imagine)
---------------------------------------------------------------------------
Jinny Uppal,                                   E-mail: jinnyu@usa.net
SCS,Florida International University,                  juppal01@cs.fiu.edu
Miami, Florida (The SunShine State)      Phone (Work): 305-348-6238
---------------------------------------------------------------------------



To unsubscribe send a note to majordomo@cs.fiu.edu with the body of the message
being: unsubscribe cadse-orb