Bill Blogs in C#

Bill Wagner discusses C#, LINQ, and other items of interest

Discussion on Constructor Chaining / Accumulative Construction
Peter Ritchie posted an alternative strategy

Peter Ritchie wrote a post here on chaining constructors.

His recommendation is:

Polymorphic constructors should be called from most specific to least specific.

He makes some good points about that, but I do disagree. I agree with the idea of using accumulative construction, or, as I called it, constructor chaining. That's the subject of Item 14 in Effective C#. All my examples in that item took the opposite approach to Peter: I chained the constructors from the least specific to the most specific. 

After looking at both versions, I think it's a matter of style. The only advantage of chaining from least specific to most specific is that it puts all the initialization logic in one place: the most specific constructor. I believe that will make it more maintainable over time, but I can't point to any particular reason for it.



Published Wednesday, May 23, 2007 10:00 PM by wwagner
Filed under:

Comments

No Comments