c# - Instance variables vs parameter passing? Is there an argument? -


so,

i have been working on re-factoring legacy code , have found myself questioning validity of of re-factoring decisions have been making. 1 such query has been use of instance variables object sharing between methods within object.

specifically, there number of places constructors & methods have been split , local variables promoted instance variables, allowing access separate methods. this, me, seems wrong. breaks encapsulation, alters scope , can affect life cycle, however, of these classes performance related , wonder implication of re-factoring these methods use parameter passing instead may be?

more point wonder whether assumptions hold water? parameter passing of objects preferable instance variables when comes sharing between private methods?

on plus site way wont have pass arguments other methods. when method has more 3 arguments (according robert martin's clean code) readability of code starts decrease fast. think should mix these 2 methods bet best result.

what if can extract new class part of existing one. when part of methods use these instance fields, perhaps methods doing can abstracted. way can create new class instance fields constructor arguments or properties , instantiate it.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -