I have a class StreamCopyOperation which provides me such things like the average speed of the copy operation and other informations.
Now I have a constructor which looks like
public StreamCopyOperation(Stream source, Stream target, int bufferSize, int updateInterval)
{
//Initialize values
}
and a method
public void CopyStream()
{
//Copy the streams, send the progress updates, etc...
}
Now I don’t know if all the arguments should be in the constructor or the streams should be passed in the method like this:
public void CopyStream(Stream source, Stream target)
{
//Copy the streams, send the progress updates, etc...
}
and the constructor gets only the buffer size and the update interval passed.
Or maybe everything should be in the CopyStream method.
Is there something like a best practice or is this just a design decision?
I think it’s a design decision based upon how you expect the class to be used.
If it’s a use-once type of class, then maybe all arguments should be passed into the constructor and then you set any other properties and then call CopyStream (with no arguments).
But, if you expect the stream parameters to change, then don’t pass them into the constructor and have the values be passed into the CopyStream method.
Lastly, if it really is more of a use-once type of class, then maybe you should consider the class being a
staticclass andCopyStreambeing static — saves you a line of code and makes the class more of a helper type of class.Hope this helps!