All pastes #553300 Raw Edit

iakovz

public text v1 · immutable
·published 2007-06-09 17:32 UTC
rendered paste body
/// pidgin C++



##INHERITANCE when it's possible to broke invariant##



class A{
int foobar; ..

public:
foo () { bar().. }
bar () {..} // DOES has some contract..
};

class B : A {
public:
bar () { /* let's broke foo() - let's implement someth cruel here */ } // BROEKN bar's contract
}

... <some client code may be B's method> ...
B->foo () // THIS CALL can't guarantee A+B's INVARIANT [ A's one to be presice ]
... 

================


##DELEGATION+COMPOSITION##

class B {
A* a;
public:
...
a->foo (); // IS *SAFE* NOW <--
...
}