c# - OOP - two tables into the same object -
c# - OOP - two tables into the same object -
i have 2 tables in database used same thing, tables don't have same structure.
lets have 1 table manual requests , table automatic requests. have load both tables same gridview , i'm using custom business objects.
to illustrate question i'll phone call tmanualreqtable , tautomaticreqtable.
tmanualreqtable - id - field1 - field2 - field3 - field4 and
tautomaticreqtable - id - field1 - field3 in code, i'm using same object these 2 tables. have interface properties of both tables , i'm checking if field exists when i'm loading info object.
but i'm thinking should created 2 objects , 1 superclass abstracts methods.
what sentiment it?
i create interface irequest describes fields & methods mutual both, , interfaces & classes manualrequest , automaticrequest implement irequest , add together methods/fields unique each of them.
you can utilize irequest type incorporates either one. when iterating through can include info either, can check whether each object implements interfaces:
foreach (irequest obj in requestlist) { // stuff uses mutual interface if (obj imanualrequest) { // stuff specific manual requests } else if (obj iautomaticrequest) { // likewise } } c# oop
Comments
Post a Comment