This is something to think about for future development... for Ubercart 3.x features list.
There is a move by some in Drupal to use OO (Object Oriented) code where it makes sense - views 2 uses it and the new database layer also uses it.
The area where OO makes the most sense, is where you want to be able to swap out specific layers of code for an alternative system/module. This is very relevant with an ecommerce package like ubercart with payment gateways - you are only interested in using one payment gateway at a time. The system of hooks which we love in Drupal is cumbersome for this specific task.
At the moment ubercart has to call 'function_exists' everytime it wants to interact with a payment gateway as you just don't know if the gateway implements a certain function (this adds the requirement for lot of extra error handling everytime you want to talk to a payment gateway)
What OO offers:
Firstly there is no need for both payment methods and payment gateways, everything is just a payment method, using inheritance you can get the extra layers of payment gateways. So you just have a base class of payment method that includes all the functions that all payment methods require. You then just have a creditPayment type the extend the base paymentMethod providing anything specific to credit card payment and each credit card gateway just extend the credit payment.
a simple example, processing a credit card payment
<?php
// this is the base class which would define a function for process payment
class paymentMethod {
function process_payment() {
// this is probably empty or returns FALSE that no other payment method called
}
}
class
creditPayment extends paymentMethod() {
// don't actually have a process_payment function since this is just a shell class to handle specific stuff for credit card payments
}
class
test_gateway extends creditPayment() {
// here we override the default payment process function with our specific gateway code here
function process_payment() {
// add our gateway code here
}
}
// then in Ubercart to process the order you would just need
payment = new creditPayment(); // this would load our default gateway of test_gateway
payment->processPayment();
//which is so much simpler/cleaner to read then something like
$handler = $gateway .'_charge';
if(function_exists($handler)) {
$handler($order);
}
else {
// do something to log the error
}
?>I haven't looked much at Conditional Actions, but I think this is also a potential area that may be able to be made simpler by using OO.
This is a good listen for more info on OO in drupal:
http://www.lullabot.com/drupal-voices/drupal-voices-21-larry-garfield-ex...

