J
John
Hi,
In my years as a VB programmer, I have settled into this pattern of creating
collections classes, with an AddNew() method. AddNew() validates the
parameters, instantiates the object, adds it to the collection, and returns
it. The AddNew() method was used to get around the lack of a constructor in
VB classes.
Now I was just about to rewrite this same pattern in C#, when I realized hey
... I've got constructors, and instead of using a collection object, I can
just have a static method to return an IList or ICollection of objects. And
obviously the constructor will replace the AddNew() method ... but what
about invalid constructor parameters?
I've read that Exceptions have extra over head and should be avoided other
than for the "exception" ... So
should I create a static Create() method to my class or go with the
exceptions?
Any comments are appreciated. I'm kind of struggling to get out of the VB /
classic ASP mindset, so forgive my ignorance I'm missing something basic.
Thanks in advance.
John
In my years as a VB programmer, I have settled into this pattern of creating
collections classes, with an AddNew() method. AddNew() validates the
parameters, instantiates the object, adds it to the collection, and returns
it. The AddNew() method was used to get around the lack of a constructor in
VB classes.
Now I was just about to rewrite this same pattern in C#, when I realized hey
... I've got constructors, and instead of using a collection object, I can
just have a static method to return an IList or ICollection of objects. And
obviously the constructor will replace the AddNew() method ... but what
about invalid constructor parameters?
I've read that Exceptions have extra over head and should be avoided other
than for the "exception" ... So
should I create a static Create() method to my class or go with the
exceptions?
Any comments are appreciated. I'm kind of struggling to get out of the VB /
classic ASP mindset, so forgive my ignorance I'm missing something basic.
Thanks in advance.
John