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