Class giving back information

S

Snyke

My problem is that I have a Class (a socket-class to be precise) that
generates data (eg. it fetches a HTML document over an HTTP
connection).
This data is to be elaborated later by another class.
How do I communicate the data from one object to another?
What is a better style:
1) Add a member variable to the socket which points to the data
container in the elaborator.
2) Call the elaborator (create and execute) from within the socket
class.
3) Make an external (in the function that calls the socket) data
container which is shared with both objects.
4) Anything you may think of ...
 
K

Karl Heinz Buchegger

Snyke said:
My problem is that I have a Class (a socket-class to be precise) that
generates data (eg. it fetches a HTML document over an HTTP
connection).
This data is to be elaborated later by another class.
How do I communicate the data from one object to another?
What is a better style:
1) Add a member variable to the socket which points to the data
container in the elaborator.
2) Call the elaborator (create and execute) from within the socket
class.
3) Make an external (in the function that calls the socket) data
container which is shared with both objects.
4) Anything you may think of ...

I opt for 4)

class Data
{
....
};

class Fetcher
{
...
bool Fetch( Data& FetchedData );
};

class Elaborator
{
...
void Elaborate( const Data& TheData );
};

int main()
{
Data TheData;
Fetcher TheFetcher;
Elaborator TheElaborator;

if( TheFetcher.Fetch( TheData ) )
TheElaborator.Elaborate( TheData );
else
cout << "An error has occoured during fetching the data\n";
}
 
A

Anil Mamede

Data {
....
};

Socket {
........

Data getData();
}

Elaborate {
elaborateData(Data &data) {
if(!data.isNull()) {
// Treatment
}
}
.....
}

Anil Mamede
 

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

Members online

Forum statistics

Threads
474,172
Messages
2,570,934
Members
47,477
Latest member
ColumbusMa

Latest Threads

Top