I am having trouble with avoiding repeating parts in methods. I have class with multiple methods. I have some kind of validation method that should be invoked in the begining of each method or before each method is invoked. For exmple:
public class TestClass
{
public Test(){}
private void Validate(){ // some code }
public IList<User> GetUsers()
{
Validate();
//other content
}
public IList<Product> GetProducts()
{
Validate();
//other content
}
public IList<Role> GetRoles()
{
Validate();
//other content
}
public Product CreateProduct()
{
Validate();
//other content
}
}
Is there better approach for doing that instead of invoking Validate() in each method?