|
Posted by Jerry Stuckle on June 22, 2008, 10:23 pm
Please log in for more thread options
André Hänsel wrote:
> Hi,
>
> I am writing a library to access a web service and perform several
> transaction with this web service:
>
> class ErpInterfaceTransaction
> {
> private $erpinterface,
> $transactionid;
>
> public function __construct($erpinterface)
> {
> $this->erpinterface = $erpinterface;
> $this->transactionid = uniqid();
> }
>
> public function place_order()
> {
> file_get_contents('http://gateway/process.php?token='.$this-
>> erpinterface->token.'&action=place_order');
> }
> }
>
> class ErpInterface
> {
> public $token;
>
> public function begin_transaction()
> {
> return new ErpInterfaceTransaction($this);
> }
> }
>
> Should I make the ErpInterfaceTransaction class extend the
> ErpInterface class?
> I need to make $token public because the transactions need it (see
> "$this->erpinterface->token"). Can I avoid this?
> What is the preferred design pattern for such a construction?
>
> Regards,
> André
>
André,
The easiest way to answer that is to use "is-a" thinking, i.e. "Is an
Employee a type of Person?" "Is a Truck a type of Vegetable?"
In the first case, the answer is yes - so Employee should extend Person.
In the second case, the answer is no - so a Truck should not extend
Vegetable (although the truck may contain vegetables).
So - "Is an ErpInterfaceTransaction" a type of "ErpInterface"? It looks
like not - rather, the transaction USES the interface. So the interface
should be a member of transaction object.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
|