design - Transforming an object implicitly -
The following code shows a pattern that I sometimes see, where the object is transformed into one another Because it is passed as a parameter in a number of method call
var o = New MyReferenceType (); DoSomeWorkAndPossiblyModifyO (o); DoYetMoreWorkAndPossiblyFurtherModifyO (o); // now use o ...
This seems to me wrong (it seems difficult to object-oriented). Is it acceptable?
This is acceptable, but generally bad style. As always, the "good" approach is:
twosmwork and authoring (& amp; o); // Clear reference means we will accept changes o = DoSomeWorkAndReturnModified (o); // More elastic because you often want to keep the original
The approach you presented is understandable when oh is huge, and it's making a copy in memory, the question Do not use it, or if it is a function then you (and some other = private) do not use it often and do not want to bother with & amp; Sentence - Configuration. Otherwise it is laziness that there are some difficulties in identifying the bug.
Comments
Post a Comment