Which code is more correct from a design point of view.
Such:
public List<String> getStringList(int expression){ List<String> list; switch(expression){ case 1: list = getList1(); break; case 2: list = getList2(); break; ... } return list; } Or this:
public List<String> getStringList(int expression){ switch(expression){ case 1: return getList1(); case 2: return getList2(); ... } } At the moment we do not change or predict that we need to change the list in the getStringList function.
I would like to read a reasonable answer in favor of one or another option.
In the first case, we have one exit point of their function, in switch we only assign the variable that we return, and in the second case, we get several exit points.
for-...; i++...; i++or...; ++i...; ++i. It all depends on the particular case, how convenient it will be, how you like, etc. In books, they often write about some ideal code in a vacuum, yes, I also read several times, for example, that in the method it is necessary that there be 1return. In practice, there will be a crutch somewhere that takes the code away from ideality and you have to push two or threereturn. The main thing is that the code is readable, effective, and so that if you need to add a new feature - you can do it without perepilivaya entire project. - iksuy