Inheritance question: How should it be done?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have class A that does everything with table A and class B that does
everything with table B.
Now I'm working on class C (which I created) which does everything with
table C AND also inserts to table A and to table B. So in my case, when I
insert to table C, I will also insert to A and B. Since I can't inherit from
two classes simultaneously and an Insert to C automatically requires an
Insert to A & B, I initially thought of having an Insert method on C that
then calls insertToC and then instantiate classes A & B and call their
respective Insert methods. Is this the correct way?

Thanks.
 
The latter is the appropriate choice. c handles its business than
instantiates any other class it needs to manage.
 
Since I can't inherit from two classes simultaneously
This is true, but in this case, completely irrelevant, as that would be
the completely wrong thing to do.
If I followed correctly, that's exactly what you want to do.
 
Actually, it seems to me that you might want to simply forget about
inheritance and wrap up all your business logic into a single class, perhaps
in more than one method. In other words, a "class" may not always equate to
"working with a single underlying data store table".

More likely, you would want to have a generic Data Access class that's
capable of dealing with any object in your database based on what information
has been sent to it. An example might be the generic SqlHelper classes from
the Data Access Application Block code from the Patterns and Pratices Group
at Microsoft.
Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top