J
JiangZemin
Hi, i wanted to get this groups opinions on a design issue ive run into:
a programmer has coded a common data access class which is supposed to be
inherited by all data access layers at my firm. This class instantiates a
connection in the constructor, relies heavily on OleDb objects by necessity,
and does stuff like returns DataReaders and creates DataSets and Command
objects.
Before using this class i looked thru the methods and noticed that there is
no exception handling, so whenever error occurs, open connections and OleDb
DataReaders and command objects never get closed/disposed.
Being a helpful fool, i suggested to this programmer that it would be good
idea to ensure that these methods clean up unmanaged resources that they
create per best practice. The response i got is that "you dont understand
the design", this decision was intentional... all code that calls this
classes methods must write their own code to cleanup these resources in
event of an error. He did not want to "restrict users of the class from
flexibility in how they handle errors".
Given that:
1. No other programmers who use this class were aware of this necessity
2. the programmer who wrote this class himself never checks for errors from
code that calls these methods
3. its not possible for others to cleanup resources created within those
methods
4. you can still pass exceptions to the caller and still dispose resources
you create.
5. there are numerous problems with applications in production which use
this data access class.
my impression is that instead of accepting that a (fairly common)
mistake/oversight was made and quickly taking basic steps to correct it,
this programmer has decided to defend the indefensible. What do you think?
Premier JiangZemin
a programmer has coded a common data access class which is supposed to be
inherited by all data access layers at my firm. This class instantiates a
connection in the constructor, relies heavily on OleDb objects by necessity,
and does stuff like returns DataReaders and creates DataSets and Command
objects.
Before using this class i looked thru the methods and noticed that there is
no exception handling, so whenever error occurs, open connections and OleDb
DataReaders and command objects never get closed/disposed.
Being a helpful fool, i suggested to this programmer that it would be good
idea to ensure that these methods clean up unmanaged resources that they
create per best practice. The response i got is that "you dont understand
the design", this decision was intentional... all code that calls this
classes methods must write their own code to cleanup these resources in
event of an error. He did not want to "restrict users of the class from
flexibility in how they handle errors".
Given that:
1. No other programmers who use this class were aware of this necessity
2. the programmer who wrote this class himself never checks for errors from
code that calls these methods
3. its not possible for others to cleanup resources created within those
methods
4. you can still pass exceptions to the caller and still dispose resources
you create.
5. there are numerous problems with applications in production which use
this data access class.
my impression is that instead of accepting that a (fairly common)
mistake/oversight was made and quickly taking basic steps to correct it,
this programmer has decided to defend the indefensible. What do you think?
Premier JiangZemin