I think the logic of printBillingLog and printOrderLog function are similar.
So I want to use a generic way to reduce the function code.
I think the code as below , but I had got stock.
Now I don't know how to create OrderLog( the constructor's paramter is Order ) and BillingLog( the constuctor's paramter is Billing) in generic way. And how to call the setAction() method in each xxxLog entity.
Can somebody teach me how to solve the problem?
Billing、BillingLog、Order、OrderLog class as below
My Way,My Pace
Manish Singh
Ranch Hand
Joined: Jan 26, 2007
Posts: 160
posted
0
Make a 'Log' interface.
Get you logger classes Order and Billing Log implement Log interface
avseq anthoy
Ranch Hand
Joined: Apr 27, 2004
Posts: 102
posted
0
Manish Singh wrote:Make a 'Log' interface.
Get you logger classes Order and Billing Log implement Log interface
Thanks for your reply.
I think the meaning as below
But the original way that conctruct BillingLog and OrderLog as below.
I still didn't know how to construct the BillingLog and OrderLog in generic way.
Can somebody teach me how to solve it ?
Thanks
You'll need an additional interface:
You'll then get implementing classes BillingLogFactory implements LogFactory<Billing, BillingLog> and OrderLogFactory implements LogFactory<Order, OrderLog>. The NewPrintLog class then changes somewhat:
For a little more performance you can make singletons out of your factories:
You can then simply pass BillingLogFactory.getInstance() to your printLog method.