B
Bob Johnson
Please note that this question is NOT about the merits of Microsoft
certification (no need to get into that here).
While taking a MS certification exam, I came across a question where it was
obvious that two out of the five choices (a multiple choice question) would
provide a workable solution to the scenario. The other chioces obviously
incorrect. The *only* difference between the two alternatives is that they
each used different constructor arguments for creating an instance of a bcl
object (the particular object is not relevant here).
Specifically, one valid alternative answer used the default constructor
(i.e. no arguments supplied - which is is valid for the class in question);
and then the very next line of code set a property of the object. The other
valid alternative answer supplied the property value as a constructor
argument (also a valid overload of the constructor for the class in
question).
To be clear, here's some p-code:
string s = "hi there";
// valid option 1
BaseClassObject obj = new BaseClassObject();
obj.SomeProperty = s; // very next line of code
// valid option 2
BaseClassObject obj = new BaseClassObject(s);
Is it generally recommended to go with either option 1 or option 2? By
"generally recommended" I'm wondering if there is some guideline that would
dictate which option I go with?
Please note that the question scenario provided absolutely no clues or
help - nothing like "accomplish xyz with as few lines as possible" - which
would have made option 2 the "correct" answer. And it didn't ask for two
ways to accomplish xyz. The question asked "which is the BEST way to do
xyz?"
Thoughts? Perspective?
And yes, I passed this exam over a year ago, but this has been bothering me
ever since.
Thanks!
certification (no need to get into that here).
While taking a MS certification exam, I came across a question where it was
obvious that two out of the five choices (a multiple choice question) would
provide a workable solution to the scenario. The other chioces obviously
incorrect. The *only* difference between the two alternatives is that they
each used different constructor arguments for creating an instance of a bcl
object (the particular object is not relevant here).
Specifically, one valid alternative answer used the default constructor
(i.e. no arguments supplied - which is is valid for the class in question);
and then the very next line of code set a property of the object. The other
valid alternative answer supplied the property value as a constructor
argument (also a valid overload of the constructor for the class in
question).
To be clear, here's some p-code:
string s = "hi there";
// valid option 1
BaseClassObject obj = new BaseClassObject();
obj.SomeProperty = s; // very next line of code
// valid option 2
BaseClassObject obj = new BaseClassObject(s);
Is it generally recommended to go with either option 1 or option 2? By
"generally recommended" I'm wondering if there is some guideline that would
dictate which option I go with?
Please note that the question scenario provided absolutely no clues or
help - nothing like "accomplish xyz with as few lines as possible" - which
would have made option 2 the "correct" answer. And it didn't ask for two
ways to accomplish xyz. The question asked "which is the BEST way to do
xyz?"
Thoughts? Perspective?
And yes, I passed this exam over a year ago, but this has been bothering me
ever since.
Thanks!
