All objetcs (p1, p2 buyer, seller) are from the same class and initially buyer and seller objects are null. Based on the type of the document I need assign p1 and p2 to either seller or buyer.
Class EmailSenderUtil{
public void sendPendingActionEmail(Document Type, PartyType p1, PartyType p2){
PartyType buyer = null;
PartyType seller = null;
/// some other computations
else if(documentType.equals(DocumentType.REQUESTFORQUOTATION)) {
assignInitiatorAsBuyer(p1, p2, buyer, seller);
// set some other variable unique to this type
}
}
private void assignInitiatorAsBuyer(PartyType p1, PartyType p2, PartyType buyer, PartyType seller) {
buyer = p1;
seller = p2;
}
private void assignInitiatorAsSeller(PartyType p1, PartyType p2, PartyType buyer, PartyType seller) {
buyer = p2;
seller = p1;
}
}
I can assign these variables in 2 lines but as the else if conditions are alot(10) inorder to reduce the redundancy I moved this assignment inside a method. But as Java is pass by value the assignments are not reflected to the parent method.
Would be much obliged If I could know is there any elegant way to perform this operation rather than copying the same assignment several times.
this.buyerandthis.sellerin your methods.this.buyer) instead of local variables is not an option?