The code for ArmedHippo is quite simple:
<?php
class ArmedHippo extends Hippo
{
var $num_mount_points;
//Constructor
function ArmedHippo()
{
parent::Hippo();
$this->addField('num_mount_points',
new DataField(DataField::TYPE_NUMERIC(), true) );
}
//Load record from DB
function load($id)
{
parent::load($id);
$this->num_mount_points = $this->getDBValue('num_mount_points');
}
//Save record to DB
function save()
{
$this->setDBValue('num_mount_points', $this->num_mount_points );
parent::save();
}
}
?>
The constructor calls Hippo’s constructor (line 5), then adds a new data field,
calls
the field it manages (line 12).
stores the value for
num_mount_points
(line 6). ArmedHippo::load()
calls
Hippo::load()
(line 11), then extracts the value forthe field it manages (line 12).
ArmedHippo::save()
stores the value for
num_mount_points
(line 16), then callsHippo::save()
(line 17).
Now we’ve got what we wanted.
without requiring changes to
can inherit from
no calls to functions that perform application utility tasks appear in
centralized in
ArmedHippo
can be added without disturbingHippo
. A weight property can be added to Hippo
,without requiring changes to
ArmedHippo
. StealthHippo
can inherit from
ArmedHippo
, with no changes to existing code. Further,no calls to functions that perform application utility tasks appear in
Hippo
,ArmedHippo
, or StealthHippo
. They arecentralized in
BusinessBase
.
BusinessBase starts like this:
<?php
class BusinessBase
{
var $table_name = null;
var $record = null;
var $_id_field = null;
}
?>
$table_name
is, of course, the name of the RDB table for the class.$record
is an associative array describing each record in the table.The array’s index is the name of a field in the table (e. g., id). The value in each array element
is a DataField object: