<?php
class X10_Control extends Control
{
function on()
{
// ...implementation code.
}
function off()
{
// ...implementation code.
}
function getStatus()
{
// ...implementation code.
}
function dim()
{
// ...implementation code.
}
function bright()
{
// ...implementation code.
}
}
?>
protocol, but may not be common in other protocols. Therefore, we add it here exclusively. Now that our X-10
protocol class is complete, we want to see how this protocol and others will apply to a home device. We’ll start
out by creating a Device class. Let’s take a look.
<?php
class Device
{
// Member variables.
var $_type;
var $_protocol;
function Device($deviceID)
{
// Grab device settings from storage.
$deviceRS = DataProvider::getDevice($deviceID);
// Assign settings to members.
$this->_type = $deviceRS->type; // LIGHT, APPLIANCE, AUDIO, etc.
$this->_protocol = $deviceRS->protocol; // "X10"
// Compose pluggable control protocol through dynamic aggregation.
aggregate( $this, $this->_protocol."_Control" );
}
function setProtocol($protocol)
{
// Clear any existing aggregation.
deaggregate( $this, $this->_protocol."_Control" );
// Update protocol.
$this->_protocol = $protocol;
// Assign new aggregation.
aggregate( $this, $this->_protocol."_Control" );
}
}
?>
In the constructor, we grab the device settings from storage, assign these settings to our instance, and
then apply the appropriate control functionality, based on the protocol specified.
functionality is composed through aggregation. Now we can swap in and out different protocols by simply
assigning a new protocol type; even at runtime. Today your garage light is X-10 compatible; tomorrow Smart House.