Pls suggest a good pattern
3 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   neal_ravindran
Posted On:   Monday, May 3, 2004 07:57 AM

I have many payment transactions to make with many payment processors. I have a struts page for each payment transaction (sale has its saleProcess struts page, credit has its creditProcess struts page). In each of the payment transaction struts pages, I need to make a call to submit the transaction to a particular payment processor. Each payment processor has its own way of processing the transaction...and the way of processing a transaction can change now and then and then would need to modify the code (manually and redeploy). Currently I use an ejb with a function (I named submitTransactionToProcessor()) that has many ifs in it..and this ejb is called from each payment transaction struts page. The ej   More>>

I have many payment transactions to make with many payment processors. I have a struts page for each payment transaction (sale has its saleProcess struts page, credit has its creditProcess struts page).



In each of the payment transaction struts pages, I need to make a call to submit the transaction to a particular payment processor. Each payment processor has its own way of processing the transaction...and the way of processing a transaction can change now and then and then would need to modify the code (manually and redeploy).


Currently I use an ejb with a function (I named submitTransactionToProcessor()) that has many ifs in it..and this ejb is called from each payment transaction struts page. The ejb submitTransactionToProcessor() function, goes like this:-


//Transaction X

if(transaction=X)

{

if(processor=A)

{

//code for processor A

}

if(processor=B)

{

//code for processor B


}


}



//Transaction Y

if(transaction=Y)

{

if(processor=A)

{

//code for processor A

}

if(processor=B)

{

//code for processor B

}


}


Question:

If there is a better pattern to my ejb-pattern solution, kindly let me know.

   <<Less

Re: Pls suggest a good pattern

Posted By:   Andrei_Melejik  
Posted On:   Friday, June 11, 2004 06:52 AM


interface ITransaction
{
}

class ATransaction implemets ITransaction
{
}

class BTransaction implemets ITransaction
{
}


interface IProcssor
{
void process(ITransaction t);
}

class AProcessor implemets IProcessor
{
void process(ITransaction t)
{
ATransaction a = (ATransaction )t;
// code here
}

}


class BProcessor implemets IProcessor
{
void process(ITransaction t)
{
BTransaction b = (BTransaction )t;
// code here
}

}


class Processor implemements IProcessor
{
void process(ITransaction t)
{

for(int i = 0; i < processors.size(); i++)
{
IProcessor p = (Processor)processors[i];
try
{
p.process(t);
break;
}
catch(IlleagalCastException e)
{
}
}
}
private Vector processors;
}

Re: Pls suggest a good pattern

Posted By:   Anonymous  
Posted On:   Wednesday, May 12, 2004 02:55 AM

This problem is nothing very particular to EJB. I suppose a good j2ee pattern will serve your purpose.



You can try with Factory pattern which will return you the Implementation class which all will be implementing a common interface with a submitTransaction function. Then you need to just get the implementation class from the factory pattern providing your transactionId etc and you get its implementation class and you can then call submitTransaction method on it. This way if you need to add one more type of payment processor, all you will require is add new implementation class and edit the factory pattern, which could read the entries from xml/properties file to make it more configurable

Re: Pls suggest a good pattern

Posted By:   Sheikh_Azad  
Posted On:   Tuesday, May 4, 2004 06:21 AM

I would have used something like this-->
Struts(Action Class)--> Talking To Business Delegate(Web Tier)
Business Delegate--->Talking to Session Facade(App Tier)

This session Facade would further Use Factory pattern to call the appropriate Processor(Local).

In Short your solution revolves around Business Delegate + Session Facade + Factory
About | Sitemap | Contact