A
ahaupt
Hi all,
At the moment we use static methods for retrieving data: Ex.
DataTable supplierDT = DAC.Supplier.GetAll();
DataTable customerDT = DAC.Customer.GetAll();
The reason we use static methods is that it's not really worth the
trouble (which might be a bad design) to instantiate a class each time
you want to do simple query. Ex:
//We'd like to avoid this
DAC.Supplier newSupplierDAC = new DAC.Supplier();
DataTable supplierDT = newSupplierDAC.GetAll();
Concerning desing, is it bad practice to have static methods in this
scenario?
Also, I've found static methods to be quite limiting, since they can't
be declared as abstract. Ex:
I'd like to have a base class with all the shared methods, and just
overide a single accessor in the inherited classes:
//Base class
abstract class Queries
{
static DataTable GetAll()
{
return SomeDataRetriever.ExecuteQuery( QueryString );
}
static QueryString
{
get
{
return "SELECT * MumboJumbo";
}
}
}
//Inherited class
class Supplier : Queries
{
static QueryString
{
get
{
return "SELECT * FROM Suppliers";
}
}
}
//But when I call
Supplier.GetAll(); //it returns "MumboJumbo" and not "Suppliers"
Any help or suggestions regarding this design will be greatly
appreciated.
Thanks, (for still reading!)
Andre
At the moment we use static methods for retrieving data: Ex.
DataTable supplierDT = DAC.Supplier.GetAll();
DataTable customerDT = DAC.Customer.GetAll();
The reason we use static methods is that it's not really worth the
trouble (which might be a bad design) to instantiate a class each time
you want to do simple query. Ex:
//We'd like to avoid this
DAC.Supplier newSupplierDAC = new DAC.Supplier();
DataTable supplierDT = newSupplierDAC.GetAll();
Concerning desing, is it bad practice to have static methods in this
scenario?
Also, I've found static methods to be quite limiting, since they can't
be declared as abstract. Ex:
I'd like to have a base class with all the shared methods, and just
overide a single accessor in the inherited classes:
//Base class
abstract class Queries
{
static DataTable GetAll()
{
return SomeDataRetriever.ExecuteQuery( QueryString );
}
static QueryString
{
get
{
return "SELECT * MumboJumbo";
}
}
}
//Inherited class
class Supplier : Queries
{
static QueryString
{
get
{
return "SELECT * FROM Suppliers";
}
}
}
//But when I call
Supplier.GetAll(); //it returns "MumboJumbo" and not "Suppliers"
Any help or suggestions regarding this design will be greatly
appreciated.
Thanks, (for still reading!)
Andre