C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Inheritance and Data Access Question

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Wed Nov 15, 2006 6:32 am    Post subject: Inheritance and Data Access Question Reply with quote



Let's say I have the following:

#include <iostream>

using namespace std;

class B
{
};

class D1 : public B
{
public:
// Header Functions are the Same
int Fh1() {return 1;}
int Fh2() {return 2;}
int Fh3() {return 3;}

// Body Functions are Unique
int Fba() {return 'a';}
int Fbb() {return 'b';}
int Fbc() {return 'c';}
};

class D2 : public B
{
public:
// Header Functions are the Same
int Fh1() {return 1;}
int Fh2() {return 2;}
int Fh3() {return 3;}

// Body Functions are Unique
int Fbx() {return 'x';}
int Fby() {return 'y';}
int Fbz() {return 'z';}
};

int ParseHeader()
{
// What should go here?
return 0;
}

int main(int argc, char* argv[])
{
D1 d1;
D2 d2;

// Parsing D1 Header
cout << "Parse D1 Header" << endl;
ParseHeader();

// Parsing D1 Body
cout << "D1 Fba = " << d1.Fba() << endl;
cout << "D1 Fbb = " << d1.Fbb() << endl;

// Parsing D2 Header
cout << "Parse D2 Header" << endl;
ParseHeader();

// Parsing D2 Body
cout << "D2 Fbx = " << d2.Fbx() << endl;
cout << "D2 Fby = " << d2.Fby() << endl;

return 0;
}

In the above, I can't modify anything in the classes D1 or D2 or B as
these classes are provided by a 3rd party tool.

The classes provide data binding for an XML messaging protocol. In
this protocol, the header for every message will have the same
structure. You will note above the header functions are the same
across the two classes Fh1(), Fh2() and Fh3().

What I would like to do is abstract out the functionality to retrieve
the header information from the messages as this will be the same
across all messages. In my example, I show this as the ParseHeader()
function. I'm looking for suggestions on the best way to accomplish
this. I tried something with multiple inheritance but I couldn't make
it work. It smells like there's an elegant way to accomplish this but
I just can't put my finger on it.

Thanks.
Dan


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.