Win a copy of Securing DevOps this week in the Security forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Code design question  RSS feed

 
Ranch Hand
Posts: 213
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm currently working on one of the assignments in the the Cattle Drive .   I want to know if it's bad design to call multiple methods from another ?   From my main method I want to call one method and from that one method I want to have option to call one or more methods depending on the condition.  So main()  calls  methodA() and methodA() may call methodB() , methodD(), and methodF() or methodA() may only call methodC() it depends on the conditions calculated in methodA(). 

Also is it correct to say that this question is about code design?
 
Sheriff
Posts: 3015
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's difficult to answer in the abstract. Generally speaking, it's perfectly fine to have a decision (if-else) in a method, and part of the resulting branches may involve calling different methods. Something to consider is whether each of your methods performs exactly one task. If you can say that methodA() performs the same task when it calls B, D, and F, as it does when it calls C, just for different starting inputs, then your design is fine. I can't think of the Cattle Drive problem that would fit this analogy, but give it go, and your nitpicker will let you know if it makes sense. That's what we're for!
 
Let's go to the waterfront with this tiny ad:
Thread Boost - a very different sort of advertising
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!