Re: Extendable envelope/letter idiom

Discussion in 'C++' started by Ivan Vecerina, Jun 24, 2003.

  1. "Anders Logg" <> wrote in message
    news:p...
    | Wouldn't this require a user of the classes to write something like
    |
    | shared_ptr<GenericMatrix> A(new SparseMatrix);
    |
    | instead of just
    |
    | Matrix A;
    |
    | ?

    You could always start with:
    typedef shared_ptr<GenericMatrix> Matrix;
    But this obviously has limits...

    | Thanks for the comments! Using a standard tool such as boost::shared_ptr<>
    is
    | probably better programming practice, but I need to assign high priority
    | to the syntax.

    The reason I mentioned boost::shared_ptr was that Matrix was
    not doing proper memory management (it lacked a copy constructor
    and assignment operator that would either copy or otherwise
    manage the sharing of the contained GenericMatrix class).

    If syntax is important, you could still use a Matrix class,
    but consider using a smart pointer internally -- or implement
    adequate memory management for a (naked) pointer.

    This matrix class could have an additional constructor taking
    a pointer to a GenericMatrix.
    This way you could write:
    Matrix A(bufPtr,rowCount,colCount); // auto-detect best type
    Matrix B( new MyClass(....) ); // use custom representation

    And users could still provide a custom factory function:
    Matrix chooseMyBestMatrixFormat(....data....);

    Matrix C( chooseMyBestMatrixFormat(....) );


    It is just preferable not to split a class hierarchy
    as was the case in the code you posted...


    hth,

    --
    Ivan Vecerina, Dr. med. <> http://www.post1.com/~ivec
    Soft Dev Manger, xitact <> http://www.xitact.com
    Brainbench MVP for C++ <> http://www.brainbench.com
    Ivan Vecerina, Jun 24, 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. cxc
    Replies:
    0
    Views:
    6,327
  2. Replies:
    1
    Views:
    879
    Oliver Wong
    Jul 10, 2006
  3. vertigo

    big letter -> small letter

    vertigo, Jul 6, 2004, in forum: Python
    Replies:
    4
    Views:
    745
    Reinhold Birkenfeld
    Jul 6, 2004
  4. Tony Meyer

    RE: big letter -> small letter

    Tony Meyer, Jul 6, 2004, in forum: Python
    Replies:
    0
    Views:
    493
    Tony Meyer
    Jul 6, 2004
  5. Andrew McNamara

    Re: big letter -> small letter

    Andrew McNamara, Jul 6, 2004, in forum: Python
    Replies:
    2
    Views:
    743
    Scott David Daniels
    Jul 6, 2004
Loading...

Share This Page