Fred said:
Thank you for the detailed answer. It won't go to waste, however, I screwed
up the question I meant to ask.
Okay. Well, I think my previous reply still at least in part answers
the question you did want to ask.
The question should have been, what is the difference between instantiating
the ContactManagerModel class in the Constructor Initializer, as opposed to
instantiating it in the constructor body?
This part is difficult to answer though, without clarification as to
what "difference" you want to know about. There's an obvious difference
in syntax. On the other hand, after the object's constructed, there's
no real practical difference.
However, based on these follow-up questions:
And, what is the execution path?
In other words, is one constructor called? Are both called? At what point
does the "new ContactManagerModel()" execute?
Using your original code example:
The parameterless constructor, which includes the constructor
initializer "this(new ContactManagerModel())" is the first constructor
for the ContactController class called as part of the constructor
execution (obviously base constructors are called prior to it, per my
previous reply).
However, before any code in the parameterless constructor body is
executed (you have none in your example, but there could be some), any
constructors specified in the constructor initializers are called. In
your example, that means the ContactController(IContactManagerModel)
constructor.
Of course, before that constructor is called, any arguments to be passed
must be available. So the instantiation of the ContactManagedModel
object passed as an argument obviously must happen before the
constructor is called.
So, this is the order of execution, with nesting to illustrate entry and
exit. When you execute "new ContactController()", you get:
ContactController() constructor is called
{
"new ContactManagedModel()" is executed
ContactController(IContactManagedModel) constructor is called with
the object instantiated in the previous line passed as the argument
{
the value of the parameter "model" is assigned to the field "_model"
}
// if there were any code in the body of ContactController,
// it would be executed here
}
Does that clear things up?
Pete