0

I'm trying to refactor old code where I encountered a repetitive pattern when calling the same method inside every single method of a class:

public class Client(){
    
    public void GetOne(int a, int b)
    {
        CreateSomething(a, b);
    
        ....
    
        }
    }
    
    public void GetTwo(int a, int b)
    {
        CreateSomething(a, b);
    
        ....
    
        }
    }
    
    
    public void GetThree(int a, int b)
    {
        CreateSomething(a, b);
    
        ....
    
        }
    }
    
    }

As a requirement, the constructor(s) cannot be changed, and I would really like to clean this up.

I read a bit about AOP, I'm not used to it. Do you think it's a good patern to use it in this case? Is there any other simpler alternative.

Thank's

dtmot
  • 1
  • In order to answer whether AOP is suited here I'd argue we'd need some more detail on what `CreateSomething` does (in relation to your class). Is it something that lies within the responsibility of the class? If so, I'd not call it an *Aspect* – Paul Kertscher Aug 19 '20 at 10:18
  • 1
    Does this answer your question? [Run a method before all methods of a class](https://stackoverflow.com/questions/9192709/run-a-method-before-all-methods-of-a-class) – Sinatr Aug 19 '20 at 10:27

0 Answers0