문제

Suppose that we have class C and our process is as follows

  1. do func1
  2. do func2
  3. do func3
  4. do func4

where each function operates on the data from the previous stage

Which is better from the point of view of system design?

  1. make each func takes an input, returns its results and pass the result to the next stage
  2. make each func operate on data members in the class c and they all return void

And if these 2 strategies are famous design patters what is the name of each design pattern?

도움이 되었습니까?

해결책

If you use option 2, and you'll pass the code to another developer. If he/she accidentally calls func3(), func4() in the middle of the code, it will be logically wrong.

If you use option 1, the developer needs to think of the parameters which will be passed through. It is less likely that he will make mistake.

Therefore, I'll go with option 1.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top