Tutorial 05, Winter 2006

 

Considering the examples we’ve seen in class, let’s try a simple case of making a Person.

 

Imagine a table defined as such:

CREATE TABLE Person (

      name VARCHAR(255) PRIMARY KEY,           

      age int(8),

      buddy_name VARCHAR(255)

      );

 

Create the following classes: Person, PersonMapper, PersonTDG

 

Create two instances of Person: Alice and Bob.

 

Alice and Bob should be mutual buddies.

 

Run this, see what happens!

 

OK, so what just happened? Why did it happen? How can we fix it?

 

The suggested first approach would be to make two more classes, PersonIdentityMap and PersonProxy. One would also want to make an Interface PersonInterface which would be implemented by both Person and PersonProxy. Lastly, in this case, a design decision is in place that only real Person objects should be stored in the PersonIdentityMap.

 

Why are we making that extra layer of indirection with the PersonInterface?

 

Based on the slides you’ve seen in class, consider the following questions while implementing your solutions:

What happens if Alice is her own buddy?

What happens inside the Mapper if Alice is asked for, but Bob (her Buddy) does not yet exist?