Click here to get back home

Design pattern for interface with transactions

 HomeNewsGroups | Search | About
 comp.lang.php    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Design pattern for interface with transactions =?ISO-8859-1?B?QW5kcukgSORuc2V 06-22-2008
Get Chitika Premium
Posted by =?ISO-8859-1?B?QW5kcukgSORuc2V on June 22, 2008, 9:58 pm
Please log in for more thread options
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 =3D $erpinterface;
                $this->transactionid =3D uniqid();
        }

        public function place_order()
        {
                file_get_contents('http://gateway/process.php?token=3D'.$this-
>erpinterface->token.'&action=3Dplace_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=E9

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
==================


Posted by =?ISO-8859-1?B?QW5kcukgSORuc2V on June 23, 2008, 8:19 am
Please log in for more thread options
> 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.

This is why I didn't make it this way, but if I did, I could have made
$token protected instead of public.

Similar ThreadsPosted
Design pattern March 23, 2008, 10:49 am
the Visitor Design Pattern November 28, 2005, 7:45 pm
The Command Design Pattern in PHP 5 November 29, 2005, 7:01 pm
The Prototype Design Pattern in PHP 5 May 16, 2006, 9:01 pm
The Adapter Design Pattern in PHP 5 June 27, 2006, 6:10 pm
Re: Site Tracker Interface Design October 8, 2007, 1:25 pm
The Builder Design Pattern using PHP5 May 3, 2006, 8:26 pm
Singleton design pattern relveance in PHP September 28, 2006, 10:05 am
FrontController Design Pattern and Code Reuse March 10, 2005, 12:29 pm
[OT] Log all transactions "efficiently" August 25, 2004, 5:16 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap