While designing a class ( in c#, or any oop lang) i always get confused with shall i have property defined in a class and use it in methods of class , or it’s good to simply have method parameters.
One problem i found in first way is that it creates dependancy (like , what if caller has forgotten to assign the value to the property etc..).
e.g. I am designing a class “myexcel” which does “export to cvs” , “Get XML” , “format excel and save”
Here shall i have “ExcelPath” as property of myexcel or shall i pass it as parameter to GetXml , export , format methods ?
Properties should define the state associated with object – the state information that qualifies say one instance from other instance. It does not make sense to store a temporal information that is valid for a single function invocation into the object state. In other words, if you make something a object property because its get used in some method then it would only make sense if the same property value is used across multiple invocation or the property get used in multiple methods.
So in your particular case, filePath should be a parameter for all save/export methods because from usage perspective, the object instance represent some data and save/export is a just a way to serialize it. The file path would be valid for that call only – it will likely to change over multiple invocations.