Boost logo

Boost :

Subject: [boost] [contract] non-public subcontracting (N1962)
From: Lorenzo Caminiti (lorcaminiti_at_[hidden])
Date: 2010-05-30 20:42:01


Hello all (and N1962 authors especially),

How should subcontracting work for non-public base classes?

I have listed a few examples below. Assume contracts were written for
all these example classes (invariants) and their functions (pre/post
conditions).

My questions are:
A) `c::p()` should subcontract; but what about any of the other member
functions of `c`, should any of them subcontract also?
B) Am I missing any other combination of member/inheritance access
level significant for deciding when to subcontract?

    class bp {
    public:
        virtual void p(void) { std::cout << "bp called" << std::endl; }
    };

    class bf {
    protected:
        virtual void f(void) { std::cout << "bg called" << std::endl; }
    };

    class bg {
    public:
        virtual void g(void) { std::cout << "bg called" << std::endl; }
    };

    class bh {
    public:
        virtual void h(void) { std::cout << "bh called" << std::endl; }
    };

    class c: public bp, public bf, protected bg, private bh {
    public:
        // This should subcontract.
        virtual void p(void) { bp::p(); }
        // Should any of the following subcontract also?
        virtual void f(void) { bf::f(); }
        virtual void g(void) { bg::g(); }
        virtual void h(void) { bh::h(); }
        // Am I missing any other relevant combination?
    };

(I do not think multiple inheritance is relevant for my questions. I
am using multiple inheritance in this example just so to have only one
derived class `c` which exercises all the use cases.)

My notes and questions:
1) All member functions of `c` are public so they will check their
pre/post conditions as in `c` and `c` class invariants.
2) But shall any `c` member functions also check their base class
invariants and/or base function pre/post conditions?
3) `c::p()` should subcontract `bp::p` pre/post and `bp` inv because
it is a public function publicly inheriting from a base public
function.
** 4) Maybe `c::f()` should subcontract `bf::f()` pre/post but not
`bf` invariant... (because `bf::f` is protected thus it does not have
to check `bf` invariant). **
** 5) Should `c::g()` and `c::h()` subcontract given that their
inheritance is not public? **

Thank you very much.

-- 
Lorenzo

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