Is there a design pattern that can help me avoid repetition DoThisStepFirst()in many methods?
class Program
{
static void Main(string[] args)
{
Method1();
Method2();
MethodN();
}
private static void DoThisStepFirst()
{
}
private static void Method1()
{
DoThisStepFirst();
}
private static void Method2()
{
DoThisStepFirst();
}
private static void MethodN()
{
DoThisStepFirst();
}
}
EDIT 1: Suffice it to say that this is a contrived example.
My actual implementation includes method signatures with parameters and nontrivial operations in each method.
EDIT 2:
- @Marc Gravell proposed aspect-oriented programming. Yes, it can help me here.
- I also think that the Chain-of-Responsibility template can also help me here.
@ Charlie Martin wanted to know more about the program. So here is what I'm actually trying to do.
- ASP.NET MVC 2 "m" "n" .
- MVC SessionState. SessionState.
DoThisStepFirst() SessionState.- SessionState, ( , " " ).