parameter-object

Passing single object vs. passing multiple parameters

走远了吗. 提交于 2019-12-20 10:05:23
问题 Suppose I have the following Class A { Foo getFoo(); Bar getBar(); Baz getBaz(); } And I need to define a function doStuff that uses Foo , Bar , Baz of one object and does some stuff I'm struggling between which method of implementing doStuff is better (suppose it would be undesirable to place doStuff inside class A ) Method A void doStuff(Foo foo, Bar bar, Baz baz) { //some operation } or Method B void doStuff(A a) { Foo foo = a.getFoo(); Bar bar = a.getBar(); Baz baz = a.getBaz(); //some

Passing single object vs. passing multiple parameters

[亡魂溺海] 提交于 2019-12-03 00:15:14
Suppose I have the following Class A { Foo getFoo(); Bar getBar(); Baz getBaz(); } And I need to define a function doStuff that uses Foo , Bar , Baz of one object and does some stuff I'm struggling between which method of implementing doStuff is better (suppose it would be undesirable to place doStuff inside class A ) Method A void doStuff(Foo foo, Bar bar, Baz baz) { //some operation } or Method B void doStuff(A a) { Foo foo = a.getFoo(); Bar bar = a.getBar(); Baz baz = a.getBaz(); //some operation } To my limited knowledge, (+ pros, - cons) Method A +It is clear exactly what parameters