Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2002-09-13 08:33:43


From: "Robert Ramey" <ramey_at_[hidden]>
[...]
> Of course, to use my system the example would have to be recast as the
following:
>
> #include "derived_path_estimation.hpp"
>
> class Path_estimation {
> void save(basic_oarchive &ar);
> void load(basci_iarchive &ar, int version);
> }; // polymorphic

Make it abstract and polymorphic to better reflect real world code:

class Path_estimation
{
public:

    virtual ~Path_estimation() {}

    void save(basic_oarchive & ar) const = 0;
    void load(basic_iarchive & ar, int version) = 0;

    double estimated_cost() const = 0;
};

> class Estimations {
> vector<Path_estimation*> path_estimations;
> };
>
> int main()
> {
> Estimations e;
> for .....
> e.path_estimations.push_back(compute_estimation(.....)) ;
> oarchive a;
> a.register_type<Derrived_Path_estimation>();
> a << e;
> }
>
> I argue that this is not a significant burden.

You may be right, but please avoid using toy/skewed examples to demonstrate
your point. In a real program, there will be more than one derived class,
and these classes will not be visible to main(), only to the translation
unit where compute_estimation resides, or to the translation units that
contain the corresponding factory functions. Also, the program might need to
serialize a Path_estimation* not once, but on multiple occasions.

[...]

> efficiency to portability aspects of template meta-programming. The
nature of posting is
> such that discussions tend toward more and more narrow, arcane and
tangential issues.

Such characterizations do not lend much weight to your arguments. Abstract
base / concrete derived classes + factory functions is a textbook example of
implementation hiding.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk