Re: Need help with good OO design

Discussion in 'C++' started by Bob Hairgrove, Jun 26, 2003.

  1. On Thu, 26 Jun 2003 15:58:10 -0000, Joey Mukherjee
    <> 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() ==
    0)
    comeBackHere();
    else
    doRead();


    --
    Bob Hairgrove
    Bob Hairgrove, Jun 26, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. SpamProof
    Replies:
    3
    Views:
    636
    SpamProof
    Dec 1, 2003
  2. David Rubin

    Re: Need help with good OO design

    David Rubin, Jun 26, 2003, in forum: C++
    Replies:
    0
    Views:
    713
    David Rubin
    Jun 26, 2003
  3. Victor Bazarov

    Re: Need help with good OO design

    Victor Bazarov, Jun 26, 2003, in forum: C++
    Replies:
    0
    Views:
    695
    Victor Bazarov
    Jun 26, 2003
  4. John Gabriele

    help: good sturdy C procedural program design

    John Gabriele, Apr 24, 2004, in forum: C Programming
    Replies:
    2
    Views:
    478
    John Gabriele
    Apr 24, 2004
  5. Kiran
    Replies:
    0
    Views:
    310
    Kiran
    Jul 3, 2007
Loading...

Share This Page