I can think of several reasons why it might make sense. Maybe it just makes sense logically to separate out the actions that methods 1 and 2 perform. Or maybe you want to call method 1 or 2 from places other than in method 3. You generally want your code to be "modular" as possible, which can often lead to patterns such as the one you bring up.
A method that only calls other methods? [closed]
Question
Would it make sense to have 3 methods such that:
Method1 performs actionA Method2 performs actionB Method3 calls Method1 and Method2 so you don't have to manually call Method1 and Method2?
Ex:
private void method1()
{
//does smth
}
private void method2()
{
//does smth else
}
private void method3()
{
class.method1();
class.method2();
}
Edit1: thanks for all the answers! =)
Solution
OTHER TIPS
Personally, I do that a lot. I think it makes sense, and can be really useful for keeping the amount of function calls down, because otherwise you'd have to call both 1 and 2.
If 3 operations make sense in the context of domain, then it is good practice, cause clients of operation3
are less coupled to your service class and logic of operation3
.
By the way if you always call operation1
and operation2
together, then you shall do this, make the two private, and decouple the clients from them.