I have some code in method C that will get executed based upon the who called it.
public void C()
{
if(A called me) { .... }
if(B called me) { .... }
}
One way is to use a flag variable. Set the variable before calling C and then inside C process the flag.
Any other ideas?
Code smell.
Why does C care about the caller ? If the code in a method is different based on who called it, maybe you need different methods
e.g. If class Baker supports Bake(cakeSpec), it should behave identically no matter if it is called by CustomerA or CustomerB. You may want to customize some aspects of the baking, via some configuration params in cakeSpec. However on the whole, Bake() should do what it says.
Need more info.. as to exactly what you’re trying to achieve.