A database system and method allows a user to write program code in a
high-level programming language that implements a class that defines the
structure of a user-defined aggregate and methods that can be invoked on
instances of the user-defined aggregate. The class is then registered
with the database system, which enforces a specific contract for
user-defined aggregates against the class. The contract comprises the
following requirements. First, the class must specify one of a plurality
of different formats for persisting instances of the user-defined
aggregate in a database store. Second, the class must comprise certain
specified methods that can be invoked on an instance of the class. Once
these requirements are satisfied, the database system enables instances
of the user-defined aggregate to be created. Preferably, the database
system stores metadata about the user-defined aggregate for subsequent
use in creating instances of the aggregate.