Developing with the SDK > Using and Writing Data Models > JavaBeans Example > The Atom, Bond, and Molecule Classes

The atoms and the bonds are represented in the application by the Java classes Atom and Bond. These classes obey the JavaBeans conventions, for example, the Atom class has a property called symbol which represents the abbreviated symbol of the element; this property can be accessed through the methods setSymbol and getSymbol.

The Atom Class

Code Sample 2.1 shows part of the Atom class.

/**
 * A class that represents an atom.
 */ 
public class Atom
{

...

  private String symbol;
  
   public String getSymbol()
  {
    return symbol;
  }

  public void setSymbol(String symbol)
  {
    this.symbol = symbol;
  }

  
}

Code Sample 2.1 Bean Property in the Atom Class

The Atom class has also a name property (the name of the element) , and an id property, which identifies the atom in the molecule.

The Bond Class

The Bond class has two properties firstAtom and secondAtom which contain the identifiers of the two atoms linked by the bond, and also a type property which can have the values single or double.

The Molecule Class

A molecule is represented by an instance of the class Molecule. A molecule contains a list of atoms and a list of bonds.

Code Sample 2.2 shows the Molecule class.

public class Molecule
{
  private ArrayList atoms = new ArrayList();
  private ArrayList bonds = new ArrayList();
  
  public Atom[] getAtoms()
  {
    return (Atom[]) atoms.toArray(new Atom[0]);
  }
  
  public Bond[] getBonds()
  {
    return (Bond[]) bonds.toArray(new Bond[0]);
  }
  
}

Code Sample 2.2 Arrays of Objects in the Molecule Class