I have to implement same logic x=y+z for after insert and after update trigger on an object. Unfortunately I cannot make use of context variables as our prototype for trigger handler is defined long ago and they have not taken these into considerations. So I am planning to implement the logic in a method in the below way. Please let me know if this is the correct way or suggest if there is any better way of doing this.
public void Samelogic(Map<..> oldMap, Map<..> newMap){
//Local variable flag
boolean flag = 0;
//After Insert
if(oldMap.isEmpty()){
if(condition1){ flag =1;}
}
//After update
else{
if(conditon2){ flag =1;}
}
if(flag ==1){
//Perform common logic
x=y+z;
}
}