Base Class or common static method?
-
I cant figure out when to use base classes and when to use common methods that just take in different parameters and do the same task, instead of having 1 method for each of my objects. ok so in my data layer (3-tier enterprise web solution), I have 4 classes: mygets, myinserts, mydeletes, myupdates. Each of these hit the database and do the appropriate work for 7 of my tables: tb1, tb2, tb3 ... tb7 mygets has these methods gettb1(tb1key), getAlltb1, gettb2(tb2key), getAlltb2 ... tb7 each returns a dataset myinserts takes all fields for tables (as sql parameters) and adds them: addtb1(field1, field2 ... ), addtb2(field1, field2, ... ) etc. same for myupdates and mydeletes. whats the best way to structure having to code the least, and have it consistent: base classes which have the common functions for each of these 4? or static methods that basically take in different parameters and get the same stuff done? which is more efficient? related question: are base classes just a better "location" to put common methods that can be used by a lot of classes? classes that derive from them? thanks M -- modified at 2:09 Tuesday 4th April, 2006
-
I cant figure out when to use base classes and when to use common methods that just take in different parameters and do the same task, instead of having 1 method for each of my objects. ok so in my data layer (3-tier enterprise web solution), I have 4 classes: mygets, myinserts, mydeletes, myupdates. Each of these hit the database and do the appropriate work for 7 of my tables: tb1, tb2, tb3 ... tb7 mygets has these methods gettb1(tb1key), getAlltb1, gettb2(tb2key), getAlltb2 ... tb7 each returns a dataset myinserts takes all fields for tables (as sql parameters) and adds them: addtb1(field1, field2 ... ), addtb2(field1, field2, ... ) etc. same for myupdates and mydeletes. whats the best way to structure having to code the least, and have it consistent: base classes which have the common functions for each of these 4? or static methods that basically take in different parameters and get the same stuff done? which is more efficient? related question: are base classes just a better "location" to put common methods that can be used by a lot of classes? classes that derive from them? thanks M -- modified at 2:09 Tuesday 4th April, 2006
Hello, Why not use static overloaded methods from a class say "DatabaseHelperClass"?
GetRows(string key,string value, string tableName) GetRows(Hashtable filter,string tableName) GetRows(string tableName)
and same for other tasks??? As far as additions/updates are concerned, you can put the values in a hashtable such that the Key represents the column name and value represents the value of the column you want to add or update in the table. with respect to the key.. For AdditionsAddRow(string tableName,Hashtable values)
For UpdatesUpdateRows(string key, string value, string tableName, Hashtable values) GetRows(Hashtable filter,string tableName, Hashtable values) UpdateRows(string tableName, Hashtable values)
you can do similar for deletions as well. Don't you think it will be a clean approach? Maqsood Ahmed - MCAD.net Kolachi Advanced Technologies http://www.kolachi.net -
I cant figure out when to use base classes and when to use common methods that just take in different parameters and do the same task, instead of having 1 method for each of my objects. ok so in my data layer (3-tier enterprise web solution), I have 4 classes: mygets, myinserts, mydeletes, myupdates. Each of these hit the database and do the appropriate work for 7 of my tables: tb1, tb2, tb3 ... tb7 mygets has these methods gettb1(tb1key), getAlltb1, gettb2(tb2key), getAlltb2 ... tb7 each returns a dataset myinserts takes all fields for tables (as sql parameters) and adds them: addtb1(field1, field2 ... ), addtb2(field1, field2, ... ) etc. same for myupdates and mydeletes. whats the best way to structure having to code the least, and have it consistent: base classes which have the common functions for each of these 4? or static methods that basically take in different parameters and get the same stuff done? which is more efficient? related question: are base classes just a better "location" to put common methods that can be used by a lot of classes? classes that derive from them? thanks M -- modified at 2:09 Tuesday 4th April, 2006
Hi You might like to try using OOP[^] :doh: Create a class for each table. Include properties for each field, and the methods that operate on those properties. Just a thought :rolleyes: ---------------------------- Be excellent to each other :) EasiReports[^] My free reporting component for WinForms.
-
Hi You might like to try using OOP[^] :doh: Create a class for each table. Include properties for each field, and the methods that operate on those properties. Just a thought :rolleyes: ---------------------------- Be excellent to each other :) EasiReports[^] My free reporting component for WinForms.
Hello, In my opinion, making a class for each table is not an optimal solution because a database might contain alot of tables, and it can expand also, which will increase the implementation cost and It may also result in code replication. If generic methods for Addition, Update, Deletion and retrieval are deviced then it won't affect much as far as implementation is concerned. Developers will only need to add functionality to use newly added tables where ever it is required without implementing new classes for each table. What you think? Maqsood Ahmed - MCAD.net Kolachi Advanced Technologies http://www.kolachi.net
-
Hello, Why not use static overloaded methods from a class say "DatabaseHelperClass"?
GetRows(string key,string value, string tableName) GetRows(Hashtable filter,string tableName) GetRows(string tableName)
and same for other tasks??? As far as additions/updates are concerned, you can put the values in a hashtable such that the Key represents the column name and value represents the value of the column you want to add or update in the table. with respect to the key.. For AdditionsAddRow(string tableName,Hashtable values)
For UpdatesUpdateRows(string key, string value, string tableName, Hashtable values) GetRows(Hashtable filter,string tableName, Hashtable values) UpdateRows(string tableName, Hashtable values)
you can do similar for deletions as well. Don't you think it will be a clean approach? Maqsood Ahmed - MCAD.net Kolachi Advanced Technologies http://www.kolachi.netyeah thats what Im doing: I have overloaded functions that do Gets, Insert, Deletes and Updates for ALL tables. My question was: where should I put these overloaded functions? in a base class or as common static methods in another class called Utils? I realized base classes are only useful for object classes, meaning non-static instances. And also, in my business layer, I do have one class for each table which becomes an object. These table objects then use my data layer to get, insert, delete and update. pretty clean huh! :) M