G
Gustaf Liljegren
This may be a question of taste, but if there is a best practice, I want
to know. I have two choises:
SomeClass s = new SomeClass(file); // Load the file
or
SomeClass s = new SomeClass();
s.Load(file); // Load the file
The object 's' is constructed from contents of a file (or maybe a
stream). Is the contructor the natural place for reading file/stream
contents into an object, or is it better done separately, in a method?
I can think of one case when there's a need for a separate Load()
method. It's when you need to change properties of the object before
feeding data into it, like in:
XmlDocument x = new XmlDocument();
x.EntityResolver = null;
x.Load(file);
to know. I have two choises:
SomeClass s = new SomeClass(file); // Load the file
or
SomeClass s = new SomeClass();
s.Load(file); // Load the file
The object 's' is constructed from contents of a file (or maybe a
stream). Is the contructor the natural place for reading file/stream
contents into an object, or is it better done separately, in a method?
I can think of one case when there's a need for a separate Load()
method. It's when you need to change properties of the object before
feeding data into it, like in:
XmlDocument x = new XmlDocument();
x.EntityResolver = null;
x.Load(file);