How do you return two values from a single method?

后端 未结 22 807
谎友^
谎友^ 2020-12-11 00:58

When your in a situation where you need to return two things in a single method, what is the best approach?

I understand the philosophy that a method should do one t

22条回答
  •  爱一瞬间的悲伤
    2020-12-11 01:48

    Not my own thoughts (Uncle Bob's):

    If there's cohesion between those two variables - I've heard him say, you're missing a class where those two are fields. (He said the same thing about functions with long parameter lists.)

    On the other hand, if there is no cohesion, then the function does more than one thing.

提交回复
热议问题