473,471 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Design pattern for interface with transactions

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é
Jun 27 '08 #1
2 1269
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.
js*******@attglobal.net
==================

Jun 27 '08 #2
On Jun 23, 4:23 am, Jerry Stuckle <jstuck...@attglobal.netwrote:
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.
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Tony Johansson | last post by:
Hello Experts! I'm reading about design patter in the GAMMA book and there is something that I don't understand. That's why I ask you. It says "Pluggable adpters. A class is more reusable when...
1
by: Tony Johansson | last post by:
Hello! I'm reading about design pattern adaptor in the GOF book and there is something that sounds strange. When you use the adaptor design pattern you have these participants. *Target -...
0
by: Tony Johansson | last post by:
Hello! I'm reading about design pattern adaptor in the GOF book and there is something that sounds strange. The text below each participant is the book explanation for each participant. I...
4
by: emma middlebrook | last post by:
Hi Straight to the point - I don't understand why System.Array derives from IList (given the methods/properties actually on IList). When designing an interface you specify a contract. Deriving...
3
by: zlst | last post by:
Many technological innovations rely upon User Interface Design to elevate their technical complexity to a usable product. Technology alone may not win user acceptance and subsequent marketability....
6
by: Daniel Santa Cruz | last post by:
Hello all, I've been trying to go over my OO Patterns book, and I decided to try to implement them in Python this time around. I figured this would help me learn the language better. Well,...
22
by: Krivenok Dmitry | last post by:
Hello All! I am trying to implement my own Design Patterns Library. I have read the following documentation about Observer Pattern: 1) Design Patterns by GoF Classic description of Observer....
0
by: AMDRIT | last post by:
I am looking for better concrete examples, as I am a bit dense, on design patterns that facilitate my goals. I have been out to the code project, planet source code, and microsoft's patterns and...
0
weaknessforcats
by: weaknessforcats | last post by:
Design Patterns: Visitor Introduction Polymorphism requires a class hierarchy where the interface to the hierarchy is in the base class. Virtual functions allow derived classes to override base...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.