Lets look at our initial classes for the example. We want to represent a pack of cards.
package org.jpox.examples;
public class Pack
{
String name=null;
String description=null;
Set cards=new HashSet();
public Pack(String name, String desc)
{
this.name = name;
this.description = desc;
}
public void addCard(Card card)
{
cards.add(card);
}
public void removeCard(Card card)
{
cards.remove(card);
}
public Set getCards()
{
return cards;
}
public int getNumberOfCards()
{
return cards.size();
}
}
public class Card
{
String suit=null;
String number=null;
Pack pack=null;
public Card(String suit,String number)
{
this.suit = suit;
this.number = number;
}
public String getSuit()
{
return suit;
}
public String getNumber()
{
return number;
}
public Pack getPack()
{
return pack;
}
public void setPack(Pack pack)
{
this.pack = pack;
}
public String toString()
{
return "The " + number + " of " + suit;
}
}
The first thing that we need to do is add a default constructor. This is a requirement of JDO. This can be private if we wish, so we add
public class Pack
{
private Pack()
{
}
...
}
public class Card
{
private Card()
{
}
...
}
|