Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Re: Need help with good OO design

Thread Tools

Re: Need help with good OO design

Bob Hairgrove
Posts: n/a
On Thu, 26 Jun 2003 15:58:10 -0000, Joey Mukherjee
<(E-Mail Removed)> wrote:

>I have a problem doing good OO design and seek some opinions of how
>to do it better.
>I have one class that is my base class called Telemetry. It opens a
>file, and reads the first few bytes (the header) of a file. Based on
>what it just read, I determine what kind of derived class I have
>(either Science or Housekeeping) and create my dervived class via
>copy constructor.
>I do work with the derived class which includes reading more data
>from the file and then I need to read a new header (i.e. the base
>class stuff).
>The code is as follows:
>while (telemetry->Good ()) {
> telemetry->ReadNextPacket ();
> if (telemetry->IsScience ()) {
> science->Copy (telemetry);
> science->ReadNextPacket ();
> // do science specific stuff
> } else {
> housekeeping->Copy (telemetry);
> housekeeping->ReadNextPacket ();
> // do housekeeping specific stuff
> }
>delete science;
>delete housekeeping;
>delete telemetry;
>Since the file pointer is essentially shared with all three classes, the
>ifstream * defined in the base pointer will get deleted too many times.
>What is the best way to handle this problem? I cannot move the specific
>stuff into the classes which the FAQ suggests.

Use a separate "factory" class to read in the file and create the
different other files.

if (google->Search("design pattern" AND "class factory")->Count() ==

Bob Hairgrove Removed)
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need good book leads on Programming C++ (Design/Coding) for high performance systems. Kiran C++ 0 07-03-2007 10:28 AM
help: good sturdy C procedural program design John Gabriele C Programming 2 04-24-2004 04:13 PM
Looking for help/resources on Writing a nice detailed design / tech design for code SpamProof Java 3 12-01-2003 06:06 AM
Re: Need help with good OO design Victor Bazarov C++ 0 06-26-2003 04:16 PM
Re: Need help with good OO design David Rubin C++ 0 06-26-2003 04:03 PM